Wrapped Rails.env in StringQuestioneer so you can do Rails.env.development? [DHH]
This commit is contained in:
parent
7cfa6ec8a3
commit
8afa725f4b
@ -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)
|
||||
|
||||
|
||||
|
@ -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'
|
||||
|
||||
|
9
activesupport/lib/active_support/string_questioneer.rb
Normal file
9
activesupport/lib/active_support/string_questioneer.rb
Normal file
@ -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
activesupport/test/string_questioneer_test.rb
Normal file
15
activesupport/test/string_questioneer_test.rb
Normal file
@ -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
|
@ -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]
|
||||
|
||||
|
||||
|
@ -37,7 +37,7 @@ def root
|
||||
end
|
||||
|
||||
def env
|
||||
RAILS_ENV
|
||||
StringQuestioneer.new(RAILS_ENV)
|
||||
end
|
||||
|
||||
def cache
|
||||
|
Loading…
Reference in New Issue
Block a user