lib/goliath/goliath.rb in goliath-0.9.4 vs lib/goliath/goliath.rb in goliath-1.0.0.beta.1
- old
+ new
@@ -8,57 +8,47 @@
module Goliath
module_function
ENVIRONMENTS = [:development, :production, :test, :staging]
+ # for example:
+ #
+ # def development?
+ # env? :development
+ # end
+ class << self
+ ENVIRONMENTS.each do |e|
+ define_method "#{e}?" do
+ warn "[DEPRECATION] `Goliath.#{e}?` is deprecated. Please use `Goliath.env?(#{e})` instead."
+ env? e
+ end
+ end
+
+ alias :prod? :production?
+ alias :dev? :development?
+ end
+
# Retrieves the current goliath environment
#
# @return [String] the current environment
def env
- @env or fail "environment has not been set"
+ @env
end
# Sets the current goliath environment
#
- # @param [String|Symbol] env the environment symbol of [dev | development | prod | production | test]
+ # @param [String|Symbol] env the environment symbol
def env=(e)
- es = case(e.to_sym)
+ @env = case(e.to_sym)
when :dev then :development
when :prod then :production
else e.to_sym
end
-
- if ENVIRONMENTS.include?(es)
- @env = es
- else
- fail "did not recognize environment: #{e}, expected one of: #{ENVIRONMENTS.join(', ')}"
- end
end
- # Determines if we are in the production environment
+ # Determines if we are in a particular environment
#
- # @return [Boolean] true if current environment is production, false otherwise
- def prod?
- env == :production
- end
-
- # Determines if we are in the development environment
- #
- # @return [Boolean] true if current environment is development, false otherwise
- def dev?
- env == :development
- end
-
- # Determines if we are in the test environment
- #
- # @return [Boolean] true if current environment is test, false otherwise
- def test?
- env == :test
- end
-
- # Determines if we are in the staging environment
- #
- # @return [Boolean] true if current environment is staging.
- def staging?
- env == :staging
+ # @return [Boolean] true if current environment matches, false otherwise
+ def env?(e)
+ env == e.to_sym
end
end