diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2008-06-03 17:44:56 -0500 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2008-06-03 17:44:56 -0500 |
commit | 8afa725f4b98a6e0ceee4792e8ebaebb6189e5f6 (patch) | |
tree | 358f418791a56620c32a48776739b4fdf39d3cb0 /activesupport | |
parent | 7cfa6ec8a37b70ec302f09929df5160ac42971e7 (diff) | |
download | rails-8afa725f4b98a6e0ceee4792e8ebaebb6189e5f6.tar.gz rails-8afa725f4b98a6e0ceee4792e8ebaebb6189e5f6.tar.bz2 rails-8afa725f4b98a6e0ceee4792e8ebaebb6189e5f6.zip |
Wrapped Rails.env in StringQuestioneer so you can do Rails.env.development? [DHH]
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/CHANGELOG | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support.rb | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/string_questioneer.rb | 9 | ||||
-rw-r--r-- | activesupport/test/string_questioneer_test.rb | 15 |
4 files changed, 28 insertions, 0 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index a6ce37ac14..894b43928f 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -4,6 +4,8 @@ * Namespace Inflector, Dependencies, OrderedOptions, and TimeZone under ActiveSupport [Josh Peek] +* 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) diff --git a/activesupport/lib/active_support.rb b/activesupport/lib/active_support.rb index 982adfb0cf..2b418a1bb7 100644 --- a/activesupport/lib/active_support.rb +++ b/activesupport/lib/active_support.rb @@ -43,6 +43,8 @@ require 'active_support/ordered_hash' 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' diff --git a/activesupport/lib/active_support/string_questioneer.rb b/activesupport/lib/active_support/string_questioneer.rb new file mode 100644 index 0000000000..7732f8b401 --- /dev/null +++ b/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
\ No newline at end of file diff --git a/activesupport/test/string_questioneer_test.rb b/activesupport/test/string_questioneer_test.rb new file mode 100644 index 0000000000..ff9d2c17f9 --- /dev/null +++ b/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
\ No newline at end of file |