aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib/action_view/file_template.rb
blob: 4921074383f715f4c0ccc75d1bc681049505f509 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# frozen_string_literal: true

require "action_view/template"

module ActionView
  class FileTemplate < Template
    def initialize(filename, handler, details)
      @filename = filename

      super(nil, filename, handler, details)
    end

    def source
      File.binread @filename
    end

    def refresh(_)
      self
    end

    # Exceptions are marshalled when using the parallel test runner with DRb, so we need
    # to ensure that references to the template object can be marshalled as well. This means forgoing
    # the marshalling of the compiler mutex and instantiating that again on unmarshalling.
    def marshal_dump # :nodoc:
      [ @identifier, @handler, @compiled, @original_encoding, @locals, @virtual_path, @updated_at, @formats, @variants ]
    end

    def marshal_load(array) # :nodoc:
      @identifier, @handler, @compiled, @original_encoding, @locals, @virtual_path, @updated_at, @formats, @variants = *array
      @compile_mutex = Mutex.new
    end
  end
end