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
16
# File 'lib/app/models/concerns/switchboard_able.rb', line 9

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

Instance Method Details

#switchboard_nameObject

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



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

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



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

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



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

def switchboard_upsert
  return unless community_access?

  switchboard_id.present? ? switchboard_update : switchboard_insert
end