Sha256: 68d609576ed74eaf6a4bd78b491d1bb16fd194b66f7b5ef696e989f859f6728a
Contents?: true
Size: 1.48 KB
Versions: 8
Compression:
Stored size: 1.48 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 def staging? ENV['RACK_ENV'] == 'staging' end module_function :staging? def production? ENV['RACK_ENV'] =~ /^prod/ end module_function :production? def development? ENV['RACK_ENV'] =~ /^dev/ end module_function :development? end # module Env end # module Support end # module Startback
Version data entries
8 entries across 8 versions & 1 rubygems