Class: Rubber::Configuration::Environment::HashValueProxy

Inherits:
Hash
  • Object
show all
Defined in:
lib/rubber/environment.rb

Direct Known Subclasses

BoundEnv

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(global, receiver) ⇒ HashValueProxy

Returns a new instance of HashValueProxy.



84
85
86
87
88
# File 'lib/rubber/environment.rb', line 84

def initialize(global, receiver)
  @global = global
  super()
  replace(receiver)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id) ⇒ Object



106
107
108
109
# File 'lib/rubber/environment.rb', line 106

def method_missing(method_id)
  key = method_id.id2name
  return self[key]
end

Instance Attribute Details

#globalObject (readonly)

Returns the value of attribute global.



82
83
84
# File 'lib/rubber/environment.rb', line 82

def global
  @global
end

Instance Method Details

#[](name) ⇒ Object



94
95
96
97
98
# File 'lib/rubber/environment.rb', line 94

def [](name)
  value = super(name)
  value = global[name] if global && !value
  return expand(value)
end

#eachObject



100
101
102
103
104
# File 'lib/rubber/environment.rb', line 100

def each
  each_key do |key|
    yield key, self[key]
  end
end

#expand(value) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/rubber/environment.rb', line 120

def expand(value)
  val = case value
    when Hash
      HashValueProxy.new(global || self, value)
    when String
      expand_string(value)
    when Enumerable
      value.collect {|v| expand(v) }
    else
      value
  end
  return val
end

#expand_string(val) ⇒ Object



111
112
113
114
115
116
117
118
# File 'lib/rubber/environment.rb', line 111

def expand_string(val)
  while val =~ /\#\{[^\}]+\}/
    val = eval('%Q{' + val + '}', binding)
  end
  val = true if val =="true"
  val = false if val == "false"
  return val
end

#rubber_instancesObject



90
91
92
# File 'lib/rubber/environment.rb', line 90

def rubber_instances
  @rubber_instances ||= Rubber::Configuration::rubber_instances
end