Sha256: ad5d021633525c45f814c61fdefed29fd733595e05d947c0fd46b26b99249810

Contents?: true

Size: 970 Bytes

Versions: 3

Compression:

Stored size: 970 Bytes

Contents

module Config
  module Factory
    class Environment

      attr_reader :name

      def initialize(name:, configs:)
        self.name = name
        self.configs = configs
      end

      def args_for(config_name)
        config_name = config_name.to_s unless config_name.is_a?(String)
        @configs[config_name]
      end

      def self.load_file(path)
        hash = YAML.load_file(path)
        fail IOError, "Unable to load YAML file #{path}" unless hash && hash.is_a?(Hash)
        load_hash(hash)
      end

      def self.load_hash(hash)
        Environment.new(name: Environments::DEFAULT_ENVIRONMENT, configs: hash)
      end

      private

      def name=(v)
        fail ArgumentError, "Environment name #{v} must be a symbol" unless v && v.is_a?(Symbol)
        @name = v
      end

      def configs=(v)
        fail ArgumentError, "Environment configs #{v} must be a hash" unless v && v.is_a?(Hash)
        @configs = v
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
config-factory-0.0.5 lib/config/factory/environment.rb
config-factory-0.0.4 lib/config/factory/environment.rb
config-factory-0.0.3 lib/config/factory/environment.rb