Class: Copypasta::Entry::ERB

Inherits:
Base
  • Object
show all
Defined in:
lib/copypasta/entry/erb.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#filename

Instance Method Summary collapse

Methods inherited from Base

#apply

Constructor Details

#initialize(filename, directory:, locals: {}, source: nil, only_if: nil) ⇒ ERB

Returns a new instance of ERB.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/copypasta/entry/erb.rb', line 11

def initialize(filename, directory:, locals: {}, source: nil, only_if: nil)
  raise "filename must be a string." unless filename.is_a?(String)
  raise "only_if must be null or a Proc." if !only_if.nil? && !only_if.is_a?(Proc)
  raise "locals must be a Hash." unless locals.is_a?(Hash)

  @filename = filename.dup.freeze
  @directory = directory.dup.freeze
  @locals = locals.dup.freeze
  @source = (source || "#{filename}.erb").dup.freeze
  @only_if = only_if
end

Instance Attribute Details

#localsObject (readonly)

Returns the value of attribute locals.



9
10
11
# File 'lib/copypasta/entry/erb.rb', line 9

def locals
  @locals
end

#sourceObject (readonly)

Returns the value of attribute source.



8
9
10
# File 'lib/copypasta/entry/erb.rb', line 8

def source
  @source
end