Sha256: 6a8ae98b4b2cb15b9a75f21eabedbe0814791dda5444ff70277bb88a5edc7eb6

Contents?: true

Size: 1.18 KB

Versions: 29

Compression:

Stored size: 1.18 KB

Contents

module Startback
  module Support
    # This method provides the `env` and `env!` methods that
    # help querying environment variables easily.
    module Env

      # Returns an environment variable or raise an error if
      # not set.
      #
      # The result is always a String with no leading/trailing
      # spaces.
      #
      # If a block is given, the environment variable is yield
      # and the result of the block returned.
      def env!(key, default = nil, &bl)
        v = ENV[key].to_s.strip
        raise Startback::Error, "Missing ENV var `#{key}`" if v.empty?

        env(key, default, &bl)
      end
      module_function :env!

      # Returns an environment variable or the default value
      # passed as second argument.
      #
      # The result is always a String with no leading/trailing
      # spaces.
      #
      # If a block is given, the environment variable is yield
      # and the result of the block returned.
      def env(key, default = nil, &bl)
        v = ENV[key].to_s.strip
        v = v.empty? ? default : v
        v = bl.call(v) if bl && v
        v
      end
      module_function :env

    end # module Env
  end # module Support
end # module Startback

Version data entries

29 entries across 29 versions & 3 rubygems

Version Path
startback-0.19.0 lib/startback/support/env.rb
startback-0.18.2 lib/startback/support/env.rb
startback-0.18.1 lib/startback/support/env.rb
startback-0.18.0 lib/startback/support/env.rb
startback-0.17.4 lib/startback/support/env.rb
startback-0.17.3 lib/startback/support/env.rb
startback-0.17.2 lib/startback/support/env.rb
startback-0.17.1 lib/startback/support/env.rb
startback-0.17.0 lib/startback/support/env.rb
startback-0.16.0 lib/startback/support/env.rb
startback-0.15.5 lib/startback/support/env.rb
startback-0.15.4 lib/startback/support/env.rb
startback-0.15.3 lib/startback/support/env.rb
startback-0.15.2 lib/startback/support/env.rb
startback-0.15.1 lib/startback/support/env.rb
startback-0.15.0 lib/startback/support/env.rb
startback-0.14.4 lib/startback/support/env.rb
startback-0.14.3 lib/startback/support/env.rb
startback-0.14.2 lib/startback/support/env.rb
startback-0.14.1 lib/startback/support/env.rb