module Netfira::WebConnect::Model::Record::Events
Private Instance Methods
destroy_event_args()
click to toggle source
# File lib/netfira/web_connect/model/record/events.rb, line 34 def destroy_event_args @event_args ||= [ ["delete_#{self.class.single_name}", self], ['delete', self] ] end
dispatch_after_destroy()
click to toggle source
# File lib/netfira/web_connect/model/record/events.rb, line 79 def dispatch_after_destroy dispatch_with_args destroy_event_args, :after end
dispatch_after_update()
click to toggle source
# File lib/netfira/web_connect/model/record/events.rb, line 63 def dispatch_after_update # Paperclip sets this up for us, but it runs after this handler, which # means delegates don't get a saved image. Boo. We can save it twice, # because the second save (the one Paperclip set up) will no-op. attachment.save if has_file? dispatch_with_args update_event_args, :on, :after end
dispatch_around_destroy() { || ... }
click to toggle source
# File lib/netfira/web_connect/model/record/events.rb, line 75 def dispatch_around_destroy dispatch_with_args(destroy_event_args, :around) { yield } end
dispatch_around_update() { || ... }
click to toggle source
# File lib/netfira/web_connect/model/record/events.rb, line 59 def dispatch_around_update dispatch_with_args(update_event_args, :around) { yield } end
dispatch_before_destroy()
click to toggle source
# File lib/netfira/web_connect/model/record/events.rb, line 71 def dispatch_before_destroy dispatch_with_args destroy_event_args, :before, :on end
dispatch_before_update()
click to toggle source
# File lib/netfira/web_connect/model/record/events.rb, line 55 def dispatch_before_update dispatch_with_args update_event_args, :before end
dispatch_with_args(args, *timing) { || ... }
click to toggle source
# File lib/netfira/web_connect/model/record/events.rb, line 41 def dispatch_with_args(args, *timing) as_readonly do if block_given? dispatch_event timing, *args.first do dispatch_event(timing, *args.last) { as_readwrite { yield } } end else args.each { |x| dispatch_event timing, *x } end end @event_args = nil if timing.include? :after true end
update_event_args()
click to toggle source
# File lib/netfira/web_connect/model/record/events.rb, line 17 def update_event_args @event_args ||= [].tap do |args| previous = persisted? && changed_attributes.map do |key, value| # TODO: solve this type casting issue without guessing by attribute names! value = Checksum.new(value) if value and (key == 'checksum' or key == 'digest') [key, value] end.to_h event_name = previous ? 'update' : 'create' args << ["#{event_name}_#{self.class.single_name}", self] args << [event_name, self] if previous previous.merge! previous_translations if has_languages? args.each { |v| v << previous } end end end