Merge pull request #5878 from oscardelben/refactor_observed_class

Refactor Observer.observed_class
This commit is contained in:
Vijay Dev 2012-04-25 06:06:14 -07:00
commit cd65682835
1 changed files with 2 additions and 5 deletions

View File

@ -5,6 +5,7 @@ require 'active_support/core_ext/module/remove_method'
require 'active_support/core_ext/string/inflections' require 'active_support/core_ext/string/inflections'
require 'active_support/core_ext/enumerable' require 'active_support/core_ext/enumerable'
require 'active_support/deprecation' require 'active_support/deprecation'
require 'active_support/core_ext/object/try'
require 'active_support/descendants_tracker' require 'active_support/descendants_tracker'
module ActiveModel module ActiveModel
@ -212,11 +213,7 @@ module ActiveModel
# The class observed by default is inferred from the observer's class name: # The class observed by default is inferred from the observer's class name:
# assert_equal Person, PersonObserver.observed_class # assert_equal Person, PersonObserver.observed_class
def observed_class def observed_class
if observed_class_name = name[/(.*)Observer/, 1] name[/(.*)Observer/, 1].try :constantize
observed_class_name.constantize
else
nil
end
end end
end end