Sha256: bbb63995132c869529e164f37a75deb0bd5d0f6acfbba163fe9b3a612f3060a2

Contents?: true

Size: 801 Bytes

Versions: 2

Compression:

Stored size: 801 Bytes

Contents

require 'yaml'
require_relative 'environment'

module Config
  module Factory
    module Environments
      DEFAULT_ENVIRONMENT = :production
      STANDARD_ENVIRONMENTS = [:defaults, :development, :test, :stage, :staging, :production].freeze
      STANDARD_ENVIRONMENTS_NOT_FOUND = "No standard environment tags (#{STANDARD_ENVIRONMENTS.join(', ')}) found; is this really a multiple-environment configuration?"

      def self.load_file(path)
        hash = YAML.load_file(path)
        load_hash(hash)
      end

      def self.load_hash(hash)
        warn STANDARD_ENVIRONMENTS_NOT_FOUND unless STANDARD_ENVIRONMENTS.any? { |k| hash.key?(k.to_s) }
        hash.map do |k, v|
          k2 = k.to_sym
          [k2, Environment.new(name: k2, configs: v)]
        end.to_h
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
config-factory-0.0.2 lib/config/factory/environments.rb
config-factory-0.0.1 lib/config/factory/environments.rb