Class: ContextHolder

Inherits:
Struct
  • Object
show all
Defined in:
lib/thymeleaf/context/context_holder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, parent_context = nil) ⇒ ContextHolder

Returns a new instance of ContextHolder.



6
7
8
9
10
11
12
# File 'lib/thymeleaf/context/context_holder.rb', line 6

def initialize(context, parent_context = nil)
  if context.is_a? Hash
    super(ContextStruct.new(context), parent_context)
  else
    super(context, parent_context)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/thymeleaf/context/context_holder.rb', line 18

def method_missing(m, *args)
  if context.respond_to? m
    context.send(m, *args)
  elsif !parent_context.nil?
    parent_context.send(m, *args)
  end
end

Instance Attribute Details

#contextObject

Returns the value of attribute context

Returns:

  • (Object)

    the current value of context



4
5
6
# File 'lib/thymeleaf/context/context_holder.rb', line 4

def context
  @context
end

#parent_contextObject

Returns the value of attribute parent_context

Returns:

  • (Object)

    the current value of parent_context



4
5
6
# File 'lib/thymeleaf/context/context_holder.rb', line 4

def parent_context
  @parent_context
end

Instance Method Details

#evaluate(expr) ⇒ Object



14
15
16
# File 'lib/thymeleaf/context/context_holder.rb', line 14

def evaluate(expr)
  instance_eval(expr.to_s)
end

#rootObject



26
27
28
29
30
31
32
# File 'lib/thymeleaf/context/context_holder.rb', line 26

def root
  if parent_context.nil?
    context
  else
    parent_context.root
  end
end