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.



76
77
78
79
80
# File 'lib/rubber/environment.rb', line 76

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



98
99
100
101
# File 'lib/rubber/environment.rb', line 98

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

Instance Attribute Details

#globalObject (readonly)

Returns the value of attribute global.



74
75
76
# File 'lib/rubber/environment.rb', line 74

def global
  @global
end

Instance Method Details

#[](name) ⇒ Object



86
87
88
89
90
# File 'lib/rubber/environment.rb', line 86

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

#eachObject



92
93
94
95
96
# File 'lib/rubber/environment.rb', line 92

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

#expand(value) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/rubber/environment.rb', line 112

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



103
104
105
106
107
108
109
110
# File 'lib/rubber/environment.rb', line 103

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



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

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