Module: SwitchboardAble

Extended by:
ActiveSupport::Concern
Defined in:
lib/app/models/concerns/switchboard_able.rb

Overview

Objects that can be synced to switchboard. They must implement the following methods

* switchboard_name - the name of the object in switchboard land, apps, members, etc..
* switchboard_payload - the payload to send to switchboard when updating or deleting

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/app/models/concerns/switchboard_able.rb', line 9

def self.included(base)
  base.class_eval do
    field :switchboard_id, type: String
    after_save :switchboard_upsert
    before_destroy :switchboard_delete
  end
end

Instance Method Details

#switchboard_nameObject

Return the name in switchboard, must be implemented by the class



20
21
22
# File 'lib/app/models/concerns/switchboard_able.rb', line 20

def switchboard_name
  raise 'Method (switchboard_name) must be implemented by the concrete class'
end

#switchboard_payloadObject

Return the payload in switchboard, must be implemented by the class



27
28
29
# File 'lib/app/models/concerns/switchboard_able.rb', line 27

def switchboard_payload
  raise 'Method (switchboard_payload) must be implemented by the concrete class'
end

#switchboard_upsertObject

Generic handler to determine if we should insert or update this object



34
35
36
37
38
# File 'lib/app/models/concerns/switchboard_able.rb', line 34

def switchboard_upsert
  return unless community_access?

  switchboard_id.present? ? switchboard_update : switchboard_insert
end