Class: Untied::Publisher::Observer

Inherits:
ActiveRecord::Observer
  • Object
show all
Defined in:
lib/untied-publisher/observer.rb

Instance Method Summary collapse

Constructor Details

#initializeObserver

Returns a new instance of Observer.



9
10
11
12
13
14
15
16
17
# File 'lib/untied-publisher/observer.rb', line 9

def initialize
  Publisher.config.logger.info "Untied: Initializing publisher observer"

  publisher.define_callbacks
  observed = publisher.observed_classes

  self.class.send(:define_method, :observed_classes, Proc.new { observed })
  super
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, model, *args, &block) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/untied-publisher/observer.rb', line 19

def method_missing(name, model, *args, &block)
  if ActiveRecord::Callbacks::CALLBACKS.include?(name)
    options = args.first.is_a?(Hash) ? args.first : {}
    produce_event(name, model, options)
  else
    super
  end
end