Sha256: 81090e16ef4d1f89a7b283f9bad43457826e5502a9712500246ef8ea32707857

Contents?: true

Size: 1.56 KB

Versions: 22

Compression:

Stored size: 1.56 KB

Contents

require 'logger'
require 'rubber/environment'
require 'rubber/instance'
require 'rubber/generator'

module Rubber
  module Configuration

    @@configurations = {}

    def self.get_configuration(env=nil, root=nil)
      key = "#{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)
      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
    end

    class ConfigHolder
      def initialize(env=nil, root=nil)
        @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
        @instance
      end
    end

  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
rubber-2.1.0 lib/rubber/configuration.rb
rubber-2.0.8 lib/rubber/configuration.rb
rubber-2.0.7 lib/rubber/configuration.rb
rubber-2.0.6 lib/rubber/configuration.rb
rubber-2.0.5 lib/rubber/configuration.rb
rubber-2.0.4 lib/rubber/configuration.rb
rubber-2.0.3 lib/rubber/configuration.rb
rubber-2.0.2 lib/rubber/configuration.rb
rubber-2.0.1 lib/rubber/configuration.rb
rubber-2.0.0 lib/rubber/configuration.rb
rubber-2.0.0.pre12 lib/rubber/configuration.rb
rubber-2.0.0.pre11 lib/rubber/configuration.rb
rubber-2.0.0.pre10 lib/rubber/configuration.rb
rubber-2.0.0.pre9 lib/rubber/configuration.rb
rubber-2.0.0.pre8 lib/rubber/configuration.rb
rubber-2.0.0.pre7 lib/rubber/configuration.rb
rubber-2.0.0.pre6 lib/rubber/configuration.rb
rubber-2.0.0.pre5 lib/rubber/configuration.rb
rubber-2.0.0.pre4 lib/rubber/configuration.rb
rubber-2.0.0.pre3 lib/rubber/configuration.rb