Module: ReactiveObservers::Base

Extended by:
ActiveSupport::Concern
Defined in:
lib/reactive_observers/base.rb

Overview

add observe methods to appropriate class

class CustomObserver

include ReactiveObservers::Base

def changed(topic, **observer); end

end

Instance Method Summary collapse

Instance Method Details

#observe(observed, refine: nil, trigger: ReactiveObservers.configuration.default_trigger, notify: nil, **options) ⇒ ReactiveObservers::Observer::Container

create object observer for provided active record object or class

CustomObserver.new.observe(:topics) # observer is observing Topic klass CustomObserver.new.observe(Topic.first) # observer is observing specific topic

Parameters:

  • observed (Symbol, Object)

    observed object or symbol defining specific ActiveRecord class

  • refine (Proc) (defaults to: nil)

    lambda or Proc function defining observed object pre-process before It is sent to observer

  • trigger (Proc, Symbol) (defaults to: ReactiveObservers.configuration.default_trigger)

    function that is triggered inside observer during notification

  • notify (Proc, Symbol) (defaults to: nil)

    function that is used to initialize appropriate observer objects

  • options (Hash)

    additional arguments such as: on, only, fields or context

Returns:



57
58
59
# File 'lib/reactive_observers/base.rb', line 57

def observe(observed, refine: nil, trigger: ReactiveObservers.configuration.default_trigger, notify: nil, **options)
  self.class.add_observer_to_observable self, observed, options.merge(refine: refine, trigger: trigger, notify: notify)
end