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

Constructor Details

#initialize(global, roles, host) ⇒ BoundEnv



127
128
129
130
131
132
133
# File 'lib/rubber/environment.rb', line 127

def initialize(global, roles, host)
  @roles = roles
  @host = host
  bound_global = bind_config(global)
  super(nil, bound_global)
  @full_host = "#{host}.#{domain}" rescue nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id) ⇒ Object



151
152
153
154
# File 'lib/rubber/environment.rb', line 151

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

Instance Attribute Details

#full_hostObject (readonly)

Returns the value of attribute full_host.



125
126
127
# File 'lib/rubber/environment.rb', line 125

def full_host
  @full_host
end

#hostObject (readonly)

Returns the value of attribute host.



124
125
126
# File 'lib/rubber/environment.rb', line 124

def host
  @host
end

#rolesObject (readonly)

Returns the value of attribute roles.



123
124
125
# File 'lib/rubber/environment.rb', line 123

def roles
  @roles
end

Instance Method Details

#bind_config(global) ⇒ Object

Forces role/host overrides into config



136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/rubber/environment.rb', line 136

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