summaryrefslogtreecommitdiff
path: root/lib/leap_cli/config/object.rb
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2015-05-05 14:57:27 -0700
committerelijah <elijah@riseup.net>2015-05-05 14:57:27 -0700
commit80f28c3862da72172a55d3e0218faad5cdd46b4b (patch)
tree5a025b39425154c34f388ef65317154f9743ed7f /lib/leap_cli/config/object.rb
parent4b8d17980d2948c5c406ec6c2106123266c4a10b (diff)
properly bind 'global.services' and 'global.tags' in the right environment in the macros.
Diffstat (limited to 'lib/leap_cli/config/object.rb')
-rw-r--r--lib/leap_cli/config/object.rb43
1 files changed, 41 insertions, 2 deletions
diff --git a/lib/leap_cli/config/object.rb b/lib/leap_cli/config/object.rb
index a0d402b..6f71a08 100644
--- a/lib/leap_cli/config/object.rb
+++ b/lib/leap_cli/config/object.rb
@@ -10,6 +10,34 @@ require 'ya2yaml' # pure ruby yaml
module LeapCli
module Config
+
+ #
+ # A proxy for Manager that binds to a particular object
+ # (so that we can bind to a particular environment)
+ #
+ class ManagerBinding
+ def initialize(manager, object)
+ @manager = manager
+ @object = object
+ end
+
+ def services
+ @manager.env(@object.environment).services
+ end
+
+ def tags
+ @manager.env(@object.environment).tags
+ end
+
+ def provider
+ @manager.env(@object.environment).provider
+ end
+
+ def method_missing(*args)
+ @manager.send(*args)
+ end
+ end
+
#
# This class represents the configuration for a single node, service, or tag.
# Also, all the nested hashes are also of this type.
@@ -19,8 +47,6 @@ module LeapCli
class Object < Hash
attr_reader :node
- attr_reader :manager
- alias :global :manager
def initialize(manager=nil, node=nil)
# keep a global pointer around to the config manager. used a lot in the eval strings and templates
@@ -31,6 +57,19 @@ module LeapCli
@node = node || self
end
+ def manager
+ ManagerBinding.new(@manager, self)
+ end
+ alias :global :manager
+
+ def environment=(e)
+ self.store('environment', e)
+ end
+
+ def environment
+ self['environment']
+ end
+
#
# export YAML
#