lib/rubber/configuration.rb in rubber-1.15.0 vs lib/rubber/configuration.rb in rubber-2.0.0.pre1

- old
+ new

@@ -8,33 +8,44 @@ @@configurations = {} def self.get_configuration(env=nil, root=nil) key = "#{env}-#{root}" - @@configurations[key] ||= ConfigHolder.new(env, root) + unless @@configurations[key] + @@configurations[key] = ConfigHolder.new(env, root) + @@configurations[key].load() + end + return @@configurations[key] end def self.rubber_env - raise "This convenience method needs RUBBER_ENV to be set" unless RUBBER_ENV - cfg = Rubber::Configuration.get_configuration(RUBBER_ENV) + raise "This convenience method needs Rubber.env to be set" unless Rubber.env + cfg = Rubber::Configuration.get_configuration(Rubber.env) host = cfg.environment.current_host roles = cfg.instance[host].role_names rescue nil cfg.environment.bind(roles, host) end def self.rubber_instances - raise "This convenience method needs RUBBER_ENV to be set" unless RUBBER_ENV - Rubber::Configuration.get_configuration(RUBBER_ENV).instance + raise "This convenience method needs Rubber.env to be set" unless Rubber.env + Rubber::Configuration.get_configuration(Rubber.env).instance end class ConfigHolder def initialize(env=nil, root=nil) - root = "#{RUBBER_ROOT}/config/rubber" unless root - instance_cfg = "#{root}/instance" + (env ? "-#{env}.yml" : ".yml") - @environment = Environment.new("#{root}") - @instance = Instance.new(instance_cfg) + @env = env + @root = root || "#{Rubber.root}/config/rubber" + @environment = Environment.new("#{@root}") end + def load + config = @environment.bind() + instance_storage = config['instance_storage'] + instance_storage_backup = config['instance_storage_backup'] + instance_storage ||= "file:#{@root}/instance-#{@env}.yml" + @instance = Instance.new(instance_storage, :backup => instance_storage_backup) + end + def environment @environment end def instance