Sha256: b41e9ffe01853e286d1c877e21afe9173fa2315a18486103fc475aac4f742d64

Contents?: true

Size: 842 Bytes

Versions: 17

Compression:

Stored size: 842 Bytes

Contents

module Shamu
  module Features
    module Conditions

      # Match against an environment variable.
      class Env < Conditions::Condition

        # (see Condition#match?)
        def match?( context )
          variables.any? { |name, matcher| matcher.call( context.env( name ) ) }
        end

        private

          def variables
            @variables ||= hash_variables || array_variables
          end

          def hash_variables
            return unless config.is_a?( Hash )

            config.each_with_object( {} ) do |(name, value), hash|
              hash[name] = ->(v) { v == value }
            end
          end

          def array_variables
            Array( config ).each_with_object( {} ) do |name, hash|
              hash[name] = ->(v) { v.to_bool }
            end
          end

      end

    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
shamu-0.0.24 lib/shamu/features/conditions/env.rb
shamu-0.0.21 lib/shamu/features/conditions/env.rb
shamu-0.0.20 lib/shamu/features/conditions/env.rb
shamu-0.0.19 lib/shamu/features/conditions/env.rb
shamu-0.0.18 lib/shamu/features/conditions/env.rb
shamu-0.0.17 lib/shamu/features/conditions/env.rb
shamu-0.0.15 lib/shamu/features/conditions/env.rb
shamu-0.0.14 lib/shamu/features/conditions/env.rb
shamu-0.0.13 lib/shamu/features/conditions/env.rb
shamu-0.0.11 lib/shamu/features/conditions/env.rb
shamu-0.0.9 lib/shamu/features/conditions/env.rb
shamu-0.0.8 lib/shamu/features/conditions/env.rb
shamu-0.0.7 lib/shamu/features/conditions/env.rb
shamu-0.0.5 lib/shamu/features/conditions/env.rb
shamu-0.0.4 lib/shamu/features/conditions/env.rb
shamu-0.0.3 lib/shamu/features/conditions/env.rb
shamu-0.0.2 lib/shamu/features/conditions/env.rb