Module: Untied::Publisher::Doorkeeper
- Included in:
- DefaultDoorkeeper
- Defined in:
- lib/untied-publisher/doorkeeper.rb
Instance Method Summary collapse
-
#define_callbacks ⇒ Object
Defines the methods that are called when the registered callbacks fire.
-
#observed ⇒ Object
List of observed classes and callbacks.
-
#observed_classes ⇒ Object
Returns the list of classes watched.
-
#watch(*args) ⇒ Object
Watches ActiveRecord lifecycle callbacks for some Class.
Instance Method Details
#define_callbacks ⇒ Object
Defines the methods that are called when the registered callbacks fire. For example, if the publisher is defined as follows:
class MyDoorkeeper
include Untided::Publisher::Doorkeeper
def initialize
watch User, :after_create
end
end
After calling MyDoorkeeper#define_callbacks the method _notify_untied__publisher_observer_for_after_create is created on User’s model. This method is called when the after_create callback is fired.
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/untied-publisher/doorkeeper.rb', line 60 def define_callbacks logger.debug "Untied::Publisher: defining callbacks" observed.each do |(klass, callbacks, )| ActiveRecord::Callbacks::CALLBACKS.each do |callback| next unless callbacks.include?(callback) logger.debug "Untied::Publisher: seting up callback #{callback} for #{klass}" setup_observer(klass, callback, ) end end end |
#observed ⇒ Object
List of observed classes and callbacks
23 24 25 |
# File 'lib/untied-publisher/doorkeeper.rb', line 23 def observed @observed ||= [] end |
#observed_classes ⇒ Object
Returns the list of classes watched
42 43 44 |
# File 'lib/untied-publisher/doorkeeper.rb', line 42 def observed_classes observed.collect(&:first).collect(&:to_s).uniq.collect(&:constantize) end |
#watch(*args) ⇒ Object
Watches ActiveRecord lifecycle callbacks for some Class
class Doorkeeper
include Untied::Publisher::Doorkeeper
end
pub.new.watch(User, :after_create)
User.create # sends the user into the wire
35 36 37 38 39 |
# File 'lib/untied-publisher/doorkeeper.rb', line 35 def watch(*args) entity = args.shift = args.last.is_a?(Hash) ? args.pop : {} observed << [entity, args, ] end |