Sha256: 873342d3dd2b7ce17c19a4cd1c244328a7a04959e6a8abb2a27cc34b5126ab3f

Contents?: true

Size: 811 Bytes

Versions: 13

Compression:

Stored size: 811 Bytes

Contents

module Tap
  module Test
    
    # Provides for case-insensitive access to the ENV variables
    module EnvVars
      
      # Access to the case-insensitive ENV variables.  Raises an error
      # if multiple case-insensitive values are defined in ENV.
      def env(type)
        type = type.downcase
        
        # ruby 1.9 returns a hash instead of an array
        selected = ENV.select {|key, value| key.downcase == type}.to_a
        
        case selected.length
        when 0 then nil
        when 1 then selected[0][1]
        else
          raise "Multiple env values for '#{type}'" 
        end
      end
      
      # Returns true if the env_var(var) is set and matches /^true$/i
      def env_true?(var)
        (env(var) && env(var) =~ /^true$/i) ? true : false
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
bahuvrihi-tap-0.10.2 lib/tap/test/env_vars.rb
bahuvrihi-tap-0.10.3 lib/tap/test/env_vars.rb
bahuvrihi-tap-0.10.4 lib/tap/test/env_vars.rb
bahuvrihi-tap-0.10.5 lib/tap/test/env_vars.rb
bahuvrihi-tap-0.10.6 lib/tap/test/env_vars.rb
bahuvrihi-tap-0.10.7 lib/tap/test/env_vars.rb
bahuvrihi-tap-0.10.8 lib/tap/test/env_vars.rb
bahuvrihi-tap-0.11.0 lib/tap/test/env_vars.rb
bahuvrihi-tap-0.11.1 lib/tap/test/env_vars.rb
bahuvrihi-tap-0.11.2 lib/tap/test/env_vars.rb
bahuvrihi-tap-0.12.0 lib/tap/test/env_vars.rb
tap-0.11.0 lib/tap/test/env_vars.rb
tap-0.11.1 lib/tap/test/env_vars.rb