Class: ContextStruct

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/thymeleaf/context/context_struct.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash = nil) ⇒ ContextStruct

Returns a new instance of ContextStruct.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/thymeleaf/context/context_struct.rb', line 6

def initialize(hash=nil)
  @table = {}
  @hash_table = {}

  if hash && (hash.is_a? Hash)
    hash.each do |k,v|

      if v.is_a?(Array)
        other = Array.new
        v.each do |entry|
          other.push((entry.is_a?(Hash) ? self.class.new(entry) : entry))
        end
        v = other
      end

      @table[k.to_sym] = (v.is_a?(Hash) ? self.class.new(v) : v)
      @hash_table[k.to_sym] = v
      new_ostruct_member(k)

    end
  end
end

Instance Method Details

#get_private(private_var) ⇒ Object



34
35
36
# File 'lib/thymeleaf/context/context_struct.rb', line 34

def get_private(private_var)
  send(:"\##{private_var}")
end

#has_private(private_var) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/thymeleaf/context/context_struct.rb', line 38

def has_private(private_var)
  begin
    !(get_private private_var).nil?
  rescue
    false
  end
end

#set_private(private_var, value) ⇒ Object



29
30
31
32
# File 'lib/thymeleaf/context/context_struct.rb', line 29

def set_private(private_var, value)
  value = ContextStruct.new(value) if value.is_a? Hash
  send(:"\##{private_var}=", value)
end

#to_hObject



46
47
48
# File 'lib/thymeleaf/context/context_struct.rb', line 46

def to_h
  @hash_table
end