lib/envlogic/env.rb in envlogic-1.1.0 vs lib/envlogic/env.rb in envlogic-1.1.1
- old
+ new
@@ -4,11 +4,11 @@
module Envlogic
# Env module to get and set environment
class Env < String
# What environment key should be used by default
FALLBACK_ENV_KEY = 'RACK_ENV'
- # What default environment should be asumed when there's nothing else
+ # What default environment should be assumed when there's nothing else
FALLBACK_ENV = 'development'
# Postfix for ENV keys
ENV_KEY_POSTFIX = '_ENV'
# String inflecting engine
INFLECTOR = Dry::Inflector.new
@@ -18,13 +18,13 @@
# It's just a string replace alias for the envlogic compatibility
alias update replace
# @param klass [Class, Module] class/module for which we want to build a Envlogic::Env object
# @return [Envlogic::Env] envlogic env object]
+ # @note Will load appropriate environment automatically
# @example
# Envlogic::Env.new(User)
- # @note Will load appropriate environment automatically
def initialize(klass)
env = ENV[to_env_key(app_dir_name)]
env ||= ENV[to_env_key(klass.to_s)]
env ||= ENV[FALLBACK_ENV_KEY]
@@ -36,11 +36,11 @@
# @return [Boolean] true if we respond to a given missing method, otherwise false
def respond_to_missing?(method_name, include_private = false)
(method_name[-1] == '?') || super
end
- # Reacts to missing methods, from which some might be the env checkings.
+ # Reacts to missing methods, from which some might be the env checks.
# If the method ends with '?' we assume, that it is an env check
# @param method_name [String] method name for missing or env name with question mark
# @param arguments [Array] any arguments that we pass to the method
def method_missing(method_name, *arguments)
method_name[-1] == '?' ? self == method_name[0..-2] : super
@@ -58,9 +58,11 @@
.basename
.to_s
end
# Converts any string into a bash ENV key
+ # @param string [String] string we want to convert into an env key
+ # @return [String] converted name that can be an ENV key
def to_env_key(string)
INFLECTOR
.underscore(string)
.tr('/', '_')
.upcase + ENV_KEY_POSTFIX