summaryrefslogtreecommitdiff
path: root/lib
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
parent4b8d17980d2948c5c406ec6c2106123266c4a10b (diff)
properly bind 'global.services' and 'global.tags' in the right environment in the macros.
Diffstat (limited to 'lib')
-rw-r--r--lib/leap_cli.rb7
-rw-r--r--lib/leap_cli/config/manager.rb9
-rw-r--r--lib/leap_cli/config/object.rb43
-rw-r--r--lib/leap_cli/config/object_list.rb2
-rw-r--r--lib/leap_cli/core_ext/deep_dup.rb53
5 files changed, 105 insertions, 9 deletions
diff --git a/lib/leap_cli.rb b/lib/leap_cli.rb
index cbd8ac5..7b22913 100644
--- a/lib/leap_cli.rb
+++ b/lib/leap_cli.rb
@@ -20,13 +20,14 @@ require 'leap_cli/version'
require 'leap_cli/exceptions'
require 'leap_cli/leapfile'
-require 'leap_cli/core_ext/hash'
require 'leap_cli/core_ext/boolean'
+require 'leap_cli/core_ext/deep_dup'
+require 'leap_cli/core_ext/hash'
+require 'leap_cli/core_ext/json'
require 'leap_cli/core_ext/nil'
require 'leap_cli/core_ext/string'
-require 'leap_cli/core_ext/json'
-require 'leap_cli/core_ext/yaml'
require 'leap_cli/core_ext/time'
+require 'leap_cli/core_ext/yaml'
require 'leap_cli/log'
require 'leap_cli/path'
diff --git a/lib/leap_cli/config/manager.rb b/lib/leap_cli/config/manager.rb
index be95831..33b7f05 100644
--- a/lib/leap_cli/config/manager.rb
+++ b/lib/leap_cli/config/manager.rb
@@ -133,9 +133,9 @@ module LeapCli
next unless ename
log 3, :loading, '%s environment...' % ename
env(ename) do |e|
- e.services = load_all_json(Path.named_path([:service_env_config, '*', ename], @provider_dir), Config::Tag)
- e.tags = load_all_json(Path.named_path([:tag_env_config, '*', ename], @provider_dir), Config::Tag)
- e.provider = load_json( Path.named_path([:provider_env_config, ename], @provider_dir), Config::Provider)
+ e.services = load_all_json(Path.named_path([:service_env_config, '*', ename], @provider_dir), Config::Tag, :env => ename)
+ e.tags = load_all_json(Path.named_path([:tag_env_config, '*', ename], @provider_dir), Config::Tag, :env => ename)
+ e.provider = load_json( Path.named_path([:provider_env_config, ename], @provider_dir), Config::Provider, :env => ename)
e.services.inherit_from! env('default').services
e.tags.inherit_from! env('default').tags
e.provider.inherit_from! env('default').provider
@@ -315,6 +315,9 @@ module LeapCli
if obj
name = File.basename(filename).force_encoding('utf-8').sub(/^([^\.]+).*\.json$/,'\1')
obj['name'] ||= name
+ if options[:env]
+ obj.environment = options[:env]
+ end
results[name] = obj
end
end
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
#
diff --git a/lib/leap_cli/config/object_list.rb b/lib/leap_cli/config/object_list.rb
index 33ca4dd..afcc6a6 100644
--- a/lib/leap_cli/config/object_list.rb
+++ b/lib/leap_cli/config/object_list.rb
@@ -174,7 +174,7 @@ module LeapCli
if self[name]
self[name].inherit_from!(object)
else
- self[name] = object.dup
+ self[name] = object.deep_dup
end
end
end
diff --git a/lib/leap_cli/core_ext/deep_dup.rb b/lib/leap_cli/core_ext/deep_dup.rb
new file mode 100644
index 0000000..b9cf0d3
--- /dev/null
+++ b/lib/leap_cli/core_ext/deep_dup.rb
@@ -0,0 +1,53 @@
+unless Hash.method_defined?(:deep_dup)
+
+ class Array
+ def deep_dup
+ map { |it| it.deep_dup }
+ end
+ end
+
+ class Hash
+ def deep_dup
+ each_with_object(dup) do |(key, value), hash|
+ hash[key.deep_dup] = value.deep_dup
+ end
+ end
+ end
+
+ class String
+ def deep_dup
+ self.dup
+ end
+ end
+
+ class Integer
+ def deep_dup
+ self
+ end
+ end
+
+ class Float
+ def deep_dup
+ self
+ end
+ end
+
+ class TrueClass
+ def deep_dup
+ self
+ end
+ end
+
+ class FalseClass
+ def deep_dup
+ self
+ end
+ end
+
+ class NilClass
+ def deep_dup
+ self
+ end
+ end
+
+end \ No newline at end of file