diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2007-09-22 17:05:15 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2007-09-22 17:05:15 +0000 |
commit | e38ad5ddcc1de38ff485d3d78d9c72283320cdaf (patch) | |
tree | b0cc231830e85bbf214f56f37003ed084debb8d3 /activerecord | |
parent | 94d763300563e8c9fabf9f6f17386f98d0b06296 (diff) | |
download | rails-e38ad5ddcc1de38ff485d3d78d9c72283320cdaf.tar.gz rails-e38ad5ddcc1de38ff485d3d78d9c72283320cdaf.tar.bz2 rails-e38ad5ddcc1de38ff485d3d78d9c72283320cdaf.zip |
Added the possibility of using symbols in addition to concrete classes with ActiveRecord::Observer#observe #3998 [robbyrussell/tarmo]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7539 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/observer.rb | 8 |
2 files changed, 7 insertions, 3 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 7e575f4f29..4203edfd0a 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Added the possibility of using symbols in addition to concrete classes with ActiveRecord::Observer#observe #3998 [robbyrussell/tarmo] + * Added ActiveRecord::Base#to_json/from_json (currently does not support :include like to_xml) [DHH] * Added ActiveRecord::Base#from_xml [DHH]. Example: diff --git a/activerecord/lib/active_record/observer.rb b/activerecord/lib/active_record/observer.rb index 0cbd6fe2c9..9803155f2d 100644 --- a/activerecord/lib/active_record/observer.rb +++ b/activerecord/lib/active_record/observer.rb @@ -84,10 +84,11 @@ module ActiveRecord # # Observers will by default be mapped to the class with which they share a name. So CommentObserver will # be tied to observing Comment, ProductManagerObserver to ProductManager, and so on. If you want to name your observer - # differently than the class you're interested in observing, you can use the Observer.observe class method: + # differently than the class you're interested in observing, you can use the Observer.observe class method which takes + # either the concrete class (Product) or a symbol for that class (:product): # # class AuditObserver < ActiveRecord::Observer - # observe Account + # observe :account # # def after_update(account) # AuditTrail.new(account, "UPDATED") @@ -97,7 +98,7 @@ module ActiveRecord # If the audit observer needs to watch more than one kind of object, this can be specified with multiple arguments: # # class AuditObserver < ActiveRecord::Observer - # observe Account, Balance + # observe :account, :balance # # def after_update(record) # AuditTrail.new(record, "UPDATED") @@ -130,6 +131,7 @@ module ActiveRecord class << self # Attaches the observer to the supplied model classes. def observe(*models) + models.flatten.collect! { |model| model.is_a?(Symbol) ? model.to_s.camelize.constantize : model } define_method(:observed_classes) { Set.new(models) } end |