Skip to content
Browse files

use the observer class to handle the invokation 'of the method

  • Loading branch information...
1 parent 0cd99e1 commit a34e3e62f4e5ab6a509dadb2b0e23f0dc065478f @jamesgolick committed Aug 3, 2009
Showing with 5 additions and 4 deletions.
  1. +5 −4 lib/observational.rb
View
9 lib/observational.rb
@@ -4,11 +4,12 @@ module Observational
def observes(model_name, opts = {})
opts.assert_valid_keys :with, :invokes, :on
- model_klass = model_name.to_s.classify.constantize
- observer_klass = self
+ model_klass = model_name.to_s.classify.constantize
+ observer = Observer.new :method => opts[:invokes],
+ :parameters => opts[:with].nil? ? nil : [*opts[:with]],
+ :subscriber => self
model_klass.send(:"after_#{opts[:on]}") do |object|
- argument = opts.has_key?(:with) ? object.send(opts[:with]) : object
- observer_klass.send(opts[:invokes], argument)
+ observer.invoke(object)
end
end
end

0 comments on commit a34e3e6

Please sign in to comment.
Something went wrong with that request. Please try again.