Module: PubSubModelSync::SubscriberConcern::ClassMethods

Defined in:
lib/pub_sub_model_sync/subscriber_concern.rb

Instance Method Summary collapse

Instance Method Details

#ps_class_subscribe(action, settings = {}, &block) ⇒ Object

Parameters:

  • action (Symbol)

    Notification.action name

  • settings (Hash) (defaults to: {})

    @refer ps_subscribe.settings except(:id)



31
32
33
34
# File 'lib/pub_sub_model_sync/subscriber_concern.rb', line 31

def ps_class_subscribe(action, settings = {}, &block)
  settings[:to_action] ||= block if block
  add_ps_subscriber(action, nil, settings.merge(mode: :klass))
end

#ps_subscribe(actions, mapping = [], settings = {}, &block) ⇒ Object

Parameters:

  • actions (Symbol, Array<Symbol>)

    Notification.action name: save|create|update|destroy|<any_other_action>

  • mapping (Array<String,Symbol>) (defaults to: [])

    Attributes mapping with aliasing support, sample: [“id”, “full_name:name”]

  • settings (Hash<:from_klass, :to_action, :id, :if, :unless>) (defaults to: {})

    from_klass (String) Notification.class name to_action (Symbol,Proc):

    Symbol: Method to process the notification
    Proc: Block to process the notification
    

    id (Symbol,Array<Symbol,String>) attribute(s) DB primary identifier(s). Supports for mapping format. if (Symbol,Proc,Array<Symbol>) Method or block called as the conformation before calling the callback unless (Symbol,Proc,Array<Symbol>) Method or block called as the negation before calling the callback



22
23
24
25
26
27
# File 'lib/pub_sub_model_sync/subscriber_concern.rb', line 22

def ps_subscribe(actions, mapping = [], settings = {}, &block)
  settings[:to_action] ||= block if block
  Array(actions).map do |action|
    add_ps_subscriber(action, mapping, settings)
  end
end