Module: ReactiveObservers::Observable::Base

Extended by:
ActiveSupport::Concern
Includes:
DbListener
Included in:
ActiveRecord::Base
Defined in:
lib/reactive_observers/observable/base.rb

Overview

enables class to be observable automatically included to ActiveRecord::Base

Instance Method Summary collapse

Instance Method Details

#process_observer_hook_notification(action, **options) ⇒ Object

process notification from ActiveRecord hooks

Parameters:

  • action (Symbol)
  • options (Hash)


88
89
90
91
92
# File 'lib/reactive_observers/observable/base.rb', line 88

def process_observer_hook_notification(action, **options)
  return if ReactiveObservers.configuration.observed_tables.include?(self.class.table_name.to_sym) || self.class.active_observers.blank?

  process_observer_notifications action, **options
end

#process_observer_notifications(action, **options) ⇒ Object

process observer notification

Parameters:

  • action (Symbol)
  • options (Hash)


97
98
99
# File 'lib/reactive_observers/observable/base.rb', line 97

def process_observer_notifications(action, **options)
  Observable::Notification.new(self, self.class.active_observers, action, options).perform
end

#remove_observer(observer, **options) ⇒ Array

remove observer for specific object

Topic.first.remove_observer(ActivityObserver) # remove observer from first topic

Parameters:

  • observer (Class, Object)

    observer that should be removed

  • options (Hash)

    additional options that specifies which observers should be removed

Returns:

  • (Array)

    still active observers



81
82
83
# File 'lib/reactive_observers/observable/base.rb', line 81

def remove_observer(observer, **options)
  self.class.remove_observer observer, options.merge(constrain: [id])
end