module Changey::DSL::InstanceMethods
Public Class Methods
included(base)
click to toggle source
# File lib/changey/dsl.rb, line 57 def self.included(base) base.before_validation { set_changey_tracks } base.validate { run_changey_callbacks(:validate) } base.before_save { run_changey_callbacks(:before_save) } base.after_save { run_changey_callbacks(:after_save) } base.after_commit { run_changey_callbacks(:after_commit) } end
Private Instance Methods
clear_changey_tracks()
click to toggle source
# File lib/changey/dsl.rb, line 73 def clear_changey_tracks @changey_tracks_to_run = nil end
run_changey_callbacks(event)
click to toggle source
# File lib/changey/dsl.rb, line 77 def run_changey_callbacks(event) return unless @changey_tracks_to_run @changey_tracks_to_run.each do |track, (was, now)| callbacks = track.send(event.to_s.pluralize) callbacks.each do |callback| case callback when Proc instance_exec(was, now, &callback) when Symbol send(callback) end end end end
set_changey_tracks()
click to toggle source
# File lib/changey/dsl.rb, line 67 def set_changey_tracks @changey_tracks_to_run = self.class.changey_tracks.select { |t| t.run?(self) }.each_with_object({}) do |track, hash| hash[track] = [send("#{track.attribute}_was"), send(track.attribute)] end end