Class: Liquid::StaticRegisters

Inherits:
Object
  • Object
show all
Defined in:
lib/liquid/static_registers.rb

Constant Summary collapse

UNDEFINED =
Object.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(registers = {}) ⇒ StaticRegisters

Returns a new instance of StaticRegisters.



7
8
9
10
# File 'lib/liquid/static_registers.rb', line 7

def initialize(registers = {})
  @static    = registers.is_a?(StaticRegisters) ? registers.static : registers
  @registers = {}
end

Instance Attribute Details

#staticObject (readonly)

Returns the value of attribute static.



5
6
7
# File 'lib/liquid/static_registers.rb', line 5

def static
  @static
end

Instance Method Details

#[](key) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/liquid/static_registers.rb', line 16

def [](key)
  if @registers.key?(key)
    @registers[key]
  else
    @static[key]
  end
end

#[]=(key, value) ⇒ Object



12
13
14
# File 'lib/liquid/static_registers.rb', line 12

def []=(key, value)
  @registers[key] = value
end

#delete(key) ⇒ Object



24
25
26
# File 'lib/liquid/static_registers.rb', line 24

def delete(key)
  @registers.delete(key)
end

#fetch(key, default = UNDEFINED, &block) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/liquid/static_registers.rb', line 30

def fetch(key, default = UNDEFINED, &block)
  if @registers.key?(key)
    @registers.fetch(key)
  elsif default != UNDEFINED
    @static.fetch(key, default, &block)
  else
    @static.fetch(key, &block)
  end
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/liquid/static_registers.rb', line 40

def key?(key)
  @registers.key?(key) || @static.key?(key)
end