Sha256: 7c97bf86cff7887e87ab1999d9f80162b4bb8c3d0d700ae26a805e966785fb57

Contents?: true

Size: 949 Bytes

Versions: 5

Compression:

Stored size: 949 Bytes

Contents

require 'leeroy/env'
require 'leeroy/helpers'

module Leeroy
  module Helpers
    module Env
      include Leeroy::Helpers

      attr_reader :env

      def checkEnv(param, check = lambda { |x| ! x.nil? }, errmsg = "You must provide #{param} in the environment.", env = self.env)
        begin
          logger.debug "checking for '#{param}' in environment"

          # get param from env
          candidate = env.fetch(param, nil)
          logger.debug "candidate: #{candidate}"

          # check it against the check
          check_passed = check.call(candidate)
          logger.debug "check_passed: #{check_passed}"

          if check_passed
            candidate
          else
            raise errmsg
          end

        rescue NoMethodError => e
          logger.error "unable to read environment! env: #{env.inspect}"
          raise e

        rescue StandardError => e
          raise e
        end
      end

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
leeroy_app-0.5.4 lib/leeroy/helpers/env.rb
leeroy_app-0.4.0 lib/leeroy/helpers/env.rb
leeroy_app-0.3.1 lib/leeroy/helpers/env.rb
leeroy_app-0.3.0 lib/leeroy/helpers/env.rb
leeroy_app-0.2.1 lib/leeroy/helpers/env.rb