lib/timeline_fu/fires.rb in giraffesoft-timeline_fu-0.1.1 vs lib/timeline_fu/fires.rb in giraffesoft-timeline_fu-0.2.0
- old
+ new
@@ -5,17 +5,22 @@
end
module ClassMethods
def fires(event_type, opts)
raise ArgumentError, "Argument :on is mandatory" unless opts.has_key?(:on)
+ opts[:subject] = :self unless opts.has_key?(:subject)
method_name = :"fire_#{event_type}_after_#{opts[:on]}"
define_method(method_name) do
create_options = [:actor, :subject, :secondary_subject].inject({}) do |memo, sym|
- memo[sym] = send(opts[sym]) if opts[sym]
+ case opts[sym]
+ when :self
+ memo[sym] = self
+ else
+ memo[sym] = send(opts[sym]) if opts[sym]
+ end
memo
end
- create_options[:subject] ||= self
create_options[:event_type] = event_type.to_s
TimelineEvent.create!(create_options)
end