Sha256: 1436e561a92fcc1c3047586b2e65ae314f0a8f7a0d05d79b1e4ba0907712669e
Contents?: true
Size: 788 Bytes
Versions: 1
Compression:
Stored size: 788 Bytes
Contents
module TimelineFu module Fires def self.included(klass) klass.send(:extend, ClassMethods) end module ClassMethods def fires(event_type, opts) raise ArgumentError, "Argument :on is mandatory" unless opts.has_key?(:on) 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] memo end create_options[:subject] ||= self create_options[:event_type] = event_type.to_s TimelineEvent.create!(create_options) end send(:"after_#{opts[:on]}", method_name, :if => opts[:if]) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
giraffesoft-timeline_fu-0.1.1 | lib/timeline_fu/fires.rb |