Skip to content

Commit

Permalink
Wrapped Rails.env in StringQuestioneer so you can do Rails.env.develo…
Browse files Browse the repository at this point in the history
…pment? [DHH]
  • Loading branch information
dhh committed Jun 3, 2008
1 parent db1cac2 commit 9a7a696
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 1 deletion.
2 changes: 2 additions & 0 deletions activesupport/CHANGELOG
@@ -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)


Expand Down
2 changes: 2 additions & 0 deletions activesupport/lib/active_support.rb
Expand Up @@ -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'

Expand Down
9 changes: 9 additions & 0 deletions activesupport/lib/active_support/string_questioneer.rb
@@ -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
15 changes: 15 additions & 0 deletions activesupport/test/string_questioneer_test.rb
@@ -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
2 changes: 2 additions & 0 deletions railties/CHANGELOG
@@ -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]


Expand Down
2 changes: 1 addition & 1 deletion railties/lib/initializer.rb
Expand Up @@ -36,7 +36,7 @@ def root
end

def env
RAILS_ENV
StringQuestioneer.new(RAILS_ENV)
end

def cache
Expand Down

0 comments on commit 9a7a696

Please sign in to comment.