aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2008-06-03 17:44:56 -0500
committerDavid Heinemeier Hansson <david@loudthinking.com>2008-06-03 17:44:56 -0500
commit8afa725f4b98a6e0ceee4792e8ebaebb6189e5f6 (patch)
tree358f418791a56620c32a48776739b4fdf39d3cb0
parent7cfa6ec8a37b70ec302f09929df5160ac42971e7 (diff)
downloadrails-8afa725f4b98a6e0ceee4792e8ebaebb6189e5f6.tar.gz
rails-8afa725f4b98a6e0ceee4792e8ebaebb6189e5f6.tar.bz2
rails-8afa725f4b98a6e0ceee4792e8ebaebb6189e5f6.zip
Wrapped Rails.env in StringQuestioneer so you can do Rails.env.development? [DHH]
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/lib/active_support.rb2
-rw-r--r--activesupport/lib/active_support/string_questioneer.rb9
-rw-r--r--activesupport/test/string_questioneer_test.rb15
-rw-r--r--railties/CHANGELOG2
-rw-r--r--railties/lib/initializer.rb2
6 files changed, 31 insertions, 1 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
diff --git a/railties/CHANGELOG b/railties/CHANGELOG
index 4d1c86e643..abadeb693f 100644
--- a/railties/CHANGELOG
+++ b/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]
diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb
index 9e6e02e8e0..d80d014527 100644
--- a/railties/lib/initializer.rb
+++ b/railties/lib/initializer.rb
@@ -37,7 +37,7 @@ module Rails
end
def env
- RAILS_ENV
+ StringQuestioneer.new(RAILS_ENV)
end
def cache