Class: SubContext
Overview
A sub context takes in a hash of local variables that should be available in front of the current context. It basically proxies the local variables first, then failing those proxies the context.
Instance Attribute Summary collapse
-
#locals ⇒ Object
readonly
Returns the value of attribute locals.
Instance Method Summary collapse
-
#initialize(locals, context = nil) ⇒ SubContext
constructor
A new instance of SubContext.
- #method_missing(method_name, *args, &block) ⇒ Object
Constructor Details
#initialize(locals, context = nil) ⇒ SubContext
Returns a new instance of SubContext.
8 9 10 11 |
# File 'lib/volt/templates/sub_context.rb', line 8 def initialize(locals, context=nil) @locals = locals.stringify_keys @context = context end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/volt/templates/sub_context.rb', line 13 def method_missing(method_name, *args, &block) method_name = method_name.to_s if @locals[method_name] return @locals[method_name] elsif @context return @context.send(method_name, *args, &block) end raise NoMethodError.new("undefined method `#{method_name}' for \"#{self.inspect}\":#{self.class.to_s}") end |
Instance Attribute Details
#locals ⇒ Object (readonly)
Returns the value of attribute locals.
6 7 8 |
# File 'lib/volt/templates/sub_context.rb', line 6 def locals @locals end |