Class: Datacaster::Runtimes::UserContext::ContextStruct

Inherits:
Object
  • Object
show all
Defined in:
lib/datacaster/runtimes/user_context.rb

Instance Method Summary collapse

Constructor Details

#initialize(context, node) ⇒ ContextStruct

Returns a new instance of ContextStruct.



7
8
9
10
# File 'lib/datacaster/runtimes/user_context.rb', line 7

def initialize(context, node)
  @context = context
  @node = node
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/datacaster/runtimes/user_context.rb', line 12

def method_missing(m, *args)
  if !args.empty? || block_given?
    return super
  end

  if @context.key?(m)
    return @context[m]
  end

  begin
    @node.class.send_to_parent(@node, :context).public_send(m)
  rescue NoMethodError
    raise NoMethodError.new("Key #{m.inspect} is not found in the context")
  end
end