Class: Localite::Template::Env

Inherits:
Object
  • Object
show all
Defined in:
lib/localite/template.rb

Overview

the environment during run

Defined Under Namespace

Modules: Helpers

Instance Method Summary collapse

Constructor Details

#initialize(host) ⇒ Env

Returns a new instance of Env.



66
67
68
69
# File 'lib/localite/template.rb', line 66

def initialize(host)
  @host = host
  extend Helpers
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/localite/template.rb', line 46

def method_missing(sym, *args, &block)
  unless @host.is_a?(Hash)
    return @host.send(sym, *args, &block)
  end
  
  begin
    return @host.fetch(sym.to_sym)
  rescue IndexError
    :void
  end
  
  begin
    return @host.fetch(sym.to_s)
  rescue IndexError
    :void
  end

  super
end

Instance Method Details

#[](code) ⇒ Object



71
72
73
# File 'lib/localite/template.rb', line 71

def [](code)
  eval(code).to_s
end