Class: Esse::DynamicTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/esse/dynamic_template.rb

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ DynamicTemplate

Returns a new instance of DynamicTemplate.

Parameters:

  • value (Array, Hash)

    The list of dynamic_templates for mapping



6
7
8
# File 'lib/esse/dynamic_template.rb', line 6

def initialize(value)
  @hash = normalize(value)
end

Instance Method Details

#[]=(key, value) ⇒ Object



14
15
16
# File 'lib/esse/dynamic_template.rb', line 14

def []=(key, value)
  merge!(key => value)
end

#any?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/esse/dynamic_template.rb', line 24

def any?
  @hash.any?
end

#dupObject



28
29
30
# File 'lib/esse/dynamic_template.rb', line 28

def dup
  self.class.new(@hash.dup)
end

#merge!(value) ⇒ Object



10
11
12
# File 'lib/esse/dynamic_template.rb', line 10

def merge!(value)
  @hash = HashUtils.deep_merge(@hash, normalize(value))
end

#to_aObject



18
19
20
21
22
# File 'lib/esse/dynamic_template.rb', line 18

def to_a
  @hash.map do |name, value|
    { name => value }
  end
end