Sha256: 06799735a6b26b13a577869f7fd23fdea3f0cd58532c5f41d1f5307bf8640977

Contents?: true

Size: 862 Bytes

Versions: 14

Compression:

Stored size: 862 Bytes

Contents

module Climatic
  module ConfigLayers

    class EnvLayer < SuperStack::Layer

      attr_reader :filter

      def initialize(filter=nil)
        self.filter = filter
      end

      def filter=(filter)
        raise 'Invalid filter' unless [NilClass, String, Array, Regexp].include? filter.class
        @filter = filter
        load
      end

      def load(*args)
        self.replace read_filtered_environment
        @file_name = :none
        self
      end

      private

      def read_filtered_environment
        return ENV.to_hash if filter.nil?

        if filter.is_a? Array
          ENV.to_hash.select {|k, v| filter.include?(k) }
        elsif  filter.is_a? Regexp
          ENV.to_hash.select {|k, v| k =~ filter }
        elsif filter.is_a? String
          ENV.to_hash.select {|k, v| k == filter }
        end
      end

    end

  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
climatic-0.2.40 lib/climatic/config_layers/env_layer.rb
climatic-0.2.39 lib/climatic/config_layers/env_layer.rb
climatic-0.2.38 lib/climatic/config_layers/env_layer.rb
climatic-0.2.37 lib/climatic/config_layers/env_layer.rb
climatic-0.2.36 lib/climatic/config_layers/env_layer.rb
climatic-0.2.35 lib/climatic/config_layers/env_layer.rb
climatic-0.2.34 lib/climatic/config_layers/env_layer.rb
climatic-0.2.32 lib/climatic/config_layers/env_layer.rb
climatic-0.2.31 lib/climatic/config_layers/env_layer.rb
climatic-0.2.30 lib/climatic/config_layers/env_layer.rb
climatic-0.2.29 lib/climatic/config_layers/env_layer.rb
climatic-0.2.28 lib/climatic/config_layers/env_layer.rb
climatic-0.2.27 lib/climatic/config_layers/env_layer.rb
climatic-0.2.26 lib/climatic/config_layers/env_layer.rb