class Rtprov::Template::RenderingContext

Public Class Methods

new(local_vars) click to toggle source
# File lib/rtprov/template.rb, line 6
def initialize(local_vars)
  local_vars.transform_values! {|v| hash_with_accessor(v) }
  local_vars.each do |k, v|
    binding.local_variable_set(k.to_sym, v)
  end
end

Public Instance Methods

binding() click to toggle source
Calls superclass method
# File lib/rtprov/template.rb, line 13
def binding
  @binding ||= super
end

Private Instance Methods

hash_with_accessor(obj) click to toggle source

define key name method for hash recursively

# File lib/rtprov/template.rb, line 19
def hash_with_accessor(obj)
  case obj
  when Array
    obj.map {|e| hash_with_accessor(e) }
  when Hash
    obj.each_with_object({}) do |(k, v), h|
      h[k] = hash_with_accessor(v)
      h.singleton_class.define_method k do
        fetch(k)
      end
    end
  else
    obj
  end
end