Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow manual firing without a fires definition

  • Loading branch information...
commit 2898eac12bb981ff51c810455fb8d377e3827b50 1 parent 727eb7e
Zach Hale authored
Showing with 14 additions and 6 deletions.
  1. +14 −6 lib/timeline_fu/fires.rb
20 lib/timeline_fu/fires.rb
View
@@ -20,8 +20,6 @@ def fires(event_type, opts)
_if = opts.delete(:if)
_unless = opts.delete(:unless)
- event_class_names = Array(opts.delete(:event_class_name) || "TimelineEvent")
-
method_name = :"fire_#{event_type}_after_#{on}"
define_method(method_name) do
create_options = opts.keys.inject({}) do |memo, sym|
@@ -36,15 +34,25 @@ def fires(event_type, opts)
end
memo
end
- create_options[:event_type] = event_type.to_s
- event_class_names.each do |class_name|
- class_name.classify.constantize.create!(create_options)
- end
+ fire(event_type, create_options, opts)
end
send(:"after_#{on}", method_name, :if => _if, :unless => _unless)
end
+
+ def fire(event_type, create_options, opts = {})
+ create_options[:event_type] = event_type.to_s
+
+ event_class_name = opts.delete(:event_class_name) || "TimelineEvent"
+ event_class_name.classify.constantize.create!(create_options)
+ end
+ end
+
+ def fire(event_type, create_options, opts = {})
+ create_options[:subject] = self unless create_options.has_key?(:subject)
+
+ self.class.fire(event_type, create_options)
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.