Class: Rubber::Configuration::Environment::BoundEnv

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

Instance Attribute Summary collapse

Attributes inherited from HashValueProxy

#global

Instance Method Summary collapse

Methods inherited from HashValueProxy

#[], #each, #expand, #expand_string, #rubber_instances

Constructor Details

#initialize(global, roles, host) ⇒ BoundEnv

Returns a new instance of BoundEnv.



140
141
142
143
144
145
# File 'lib/rubber/environment.rb', line 140

def initialize(global, roles, host)
  @roles = roles
  @host = host
  bound_global = bind_config(global)
  super(nil, bound_global)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id) ⇒ Object



167
168
169
170
# File 'lib/rubber/environment.rb', line 167

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

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



138
139
140
# File 'lib/rubber/environment.rb', line 138

def host
  @host
end

#rolesObject (readonly)

Returns the value of attribute roles.



137
138
139
# File 'lib/rubber/environment.rb', line 137

def roles
  @roles
end

Instance Method Details

#bind_config(global) ⇒ Object

Forces role/host overrides into config



152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/rubber/environment.rb', line 152

def bind_config(global)
  global = global.clone()
  role_overrides = global.delete("roles") || {}
  host_overrides = global.delete("hosts") || {}
  Array(roles).each do |role|
    Array(role_overrides[role]).each do |k, v|
      global[k] = Environment.combine(global[k], v)
    end
  end
  Array(host_overrides[host]).each do |k, v|
    global[k] = Environment.combine(global[k], v)
  end
  return global
end

#full_hostObject



147
148
149
# File 'lib/rubber/environment.rb', line 147

def full_host
  @full_host ||= "#{host}.#{domain}" rescue nil
end