Sha256: 6601595dac3728de4ac2d7c417392cf12b4d89e892d91650602b8ac720a52d14

Contents?: true

Size: 1.21 KB

Versions: 80

Compression:

Stored size: 1.21 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}"
      @@configurations[key] ||= ConfigHolder.new(env, root)
    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)
        root = "#{RUBBER_ROOT}/config/rubber" unless root
        instance_cfg =  "#{root}/instance" + (env ? "-#{env}.yml" : ".yml")
        @environment = Environment.new("#{root}")
        @instance = Instance.new(instance_cfg)
      end

      def environment
        @environment
      end

      def instance
        @instance
      end
    end

  end
end

Version data entries

80 entries across 80 versions & 7 rubygems

Version Path
sml-rubber-0.9.1 lib/rubber/configuration.rb
sml-rubber-0.9.10 lib/rubber/configuration.rb
sml-rubber-0.9.11 lib/rubber/configuration.rb
sml-rubber-0.9.13 lib/rubber/configuration.rb
sml-rubber-0.9.3 lib/rubber/configuration.rb
sml-rubber-0.9.4 lib/rubber/configuration.rb
sml-rubber-0.9.5 lib/rubber/configuration.rb
sml-rubber-0.9.6 lib/rubber/configuration.rb
sml-rubber-0.9.7 lib/rubber/configuration.rb
sml-rubber-0.9.8 lib/rubber/configuration.rb
sml-rubber-0.9.9 lib/rubber/configuration.rb
wr0ngway-rubber-1.0.0 lib/rubber/configuration.rb
wr0ngway-rubber-1.0.1 lib/rubber/configuration.rb
rubber-1.15.0 lib/rubber/configuration.rb
rubber-1.14.1 lib/rubber/configuration.rb
rubber-1.14.0 lib/rubber/configuration.rb
rubber-1.13.2 lib/rubber/configuration.rb
rubber-1.13.1 lib/rubber/configuration.rb
axtro-rubber-1.2.3 lib/rubber/configuration.rb
axtro-rubber-1.2.2 lib/rubber/configuration.rb