Module: ActiveRecord::CommittedObserver
- Defined in:
- lib/activerecord-committed_observer.rb,
lib/activerecord-committed_observer/version.rb
Constant Summary collapse
- VERSION =
"0.0.4"
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.append_features(klass) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/activerecord-committed_observer.rb', line 6 def self.append_features(klass) if klass.method_defined?(:after_commit) ::ActiveRecord::CommittedObserver.warn_after_commit_override end super(klass) end |
.included(klass) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/activerecord-committed_observer.rb', line 14 def self.included(klass) klass.class_eval do def self.method_added(method_name) super if method_name.to_sym == :after_commit ::ActiveRecord::CommittedObserver.warn_after_commit_override end end end end |
.warn_after_commit_override ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/activerecord-committed_observer.rb', line 26 def self.warn_after_commit_override if Rails.env != 'production' warn " If you are using ActiveRecord::CommittedObserver and defined an :after_commit\n method make sure you call super to have the after_commit_on* series of methods\n called.\n\n Instead of :after_commit you can also define :after_commit_on_commit for the\n same functionality without the 'warn' message.\n\n ^ after_commit_on_commit will be called before any other after_commit_on_* methods\n SUPER_WARN\n end\nend\n" |
Instance Method Details
#after_commit(model) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/activerecord-committed_observer.rb', line 41 def after_commit(model) after_commit_on_commit(model) if respond_to?(:after_commit_on_commit) if model.respond_to?(:transaction_include_any_action?, true) # Rails 4 case when model.__send__(:transaction_include_any_action?, [:create]) then after_commit_on_create(model) if respond_to?(:after_commit_on_create) when model.__send__(:transaction_include_any_action?, [:update]) then after_commit_on_update(model) if respond_to?(:after_commit_on_update) when model.__send__(:transaction_include_any_action?, [:destroy]) then after_commit_on_destroy(model) if respond_to?(:after_commit_on_destroy) end else # Rails 3 case when model.__send__(:transaction_include_action?, :create) then after_commit_on_create(model) if respond_to?(:after_commit_on_create) when model.__send__(:transaction_include_action?, :update) then after_commit_on_update(model) if respond_to?(:after_commit_on_update) when model.__send__(:transaction_include_action?, :destroy) then after_commit_on_destroy(model) if respond_to?(:after_commit_on_destroy) end end end |