Permalink
Browse files

Wrapped Rails.env in StringQuestioneer so you can do Rails.env.develo…

…pment? [DHH]
  • Loading branch information...
1 parent db1cac2 commit 9a7a6960bedeb9d247791edfe4b5a65367535389 @dhh dhh committed Jun 3, 2008
View
@@ -1,5 +1,7 @@
*Edge*
+* Added StringQuestioneer for doing things like StringQuestioneer.new("production").production? # => true and StringQuestioneer.new("production").development? # => false [DHH]
+
* Fixed Date#end_of_quarter to not blow up on May 31st [#289 state:resolved] (Danger)
@@ -43,6 +43,8 @@
require 'active_support/ordered_options'
require 'active_support/option_merger'
+require 'active_support/string_questioneer'
+
require 'active_support/values/time_zone'
require 'active_support/duration'
@@ -0,0 +1,9 @@
+class StringQuestioneer < String
+ def method_missing(method_name, *arguments)
+ if method_name.to_s.ends_with?("?")
+ self == method_name.to_s[0..-2]
+ else
+ super
+ end
+ end
+end
@@ -0,0 +1,15 @@
+require 'abstract_unit'
+
+class StringQuestioneerTest < Test::Unit::TestCase
+ def test_match
+ assert StringQuestioneer.new("production").production?
+ end
+
+ def test_miss
+ assert !StringQuestioneer.new("production").development?
+ end
+
+ def test_missing_question_mark
+ assert_raises(NoMethodError) { StringQuestioneer.new("production").production }
+ end
+end
View
@@ -1,5 +1,7 @@
*Edge*
+* Wrapped Rails.env in StringQuestioneer so you can do Rails.env.development? [DHH]
+
* Fixed that RailsInfoController wasn't considering all requests local in development mode (Edgard Castro) [#310 state:resolved]
@@ -36,7 +36,7 @@ def root
end
def env
- RAILS_ENV
+ StringQuestioneer.new(RAILS_ENV)
end
def cache

0 comments on commit 9a7a696

Please sign in to comment.