Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Handle helper methods with method missing

Allows `Goliath.custom_env?`

`dev?` and `prod?` remain, as explicitly defined in the case statement
  • Loading branch information...
commit 0715a050e904e15ff28630e0f62f664dea65085c 1 parent 94fc17b
@seenmyfate authored
Showing with 13 additions and 9 deletions.
  1. +13 −9 lib/goliath/goliath.rb
View
22 lib/goliath/goliath.rb
@@ -17,7 +17,7 @@ def env
# Sets the current goliath environment
#
- # @param [String|Symbol] the environment symbol
+ # @param [String|Symbol] the environment symbol
def env=(e)
es = case(e.to_sym)
when :dev then :development
@@ -41,17 +41,21 @@ def dev?
env == :development
end
- # Determines if we are in the test environment
+ # Determines if we are in a custom environment
#
- # @return [Boolean] true if current environment is test, false otherwise
- def test?
- env == :test
+ # @return [Boolean] true if current environment matches, false otherwise
+ def method_missing(name, *args)
+ if name[-1] == "?"
+ env == name[0..-2].to_sym
+ else
+ super
+ end
end
- # Determines if we are in the staging environment
+ # Method missing implementation responds to predicate methods
#
- # @return [Boolean] true if current environment is staging.
- def staging?
- env == :staging
+ # @return [Boolean] true if argument is a predicate method
+ def respond_to?(method)
+ method[-1] == "?" || super
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.