Class: EmployeePhoneStatus::BroadcastSwitchboard

Inherits:
Object
  • Object
show all
Includes:
Service
Defined in:
app/services/employee_phone_status/broadcast_switchboard.rb

Overview

Broadcasts one employee's switchboard card lifecycle to authorized, scoped
Action Cable streams.

Constant Summary collapse

PERMISSIONS =
{ manage: true, read: false }.freeze
ERROR_REASONS =
{
  update: 'switchboard_broadcast_failed',
  replace: 'switchboard_broadcast_failed',
  remove: 'switchboard_remove_failed',
  refresh: 'switchboard_refresh_failed'
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Service

#attributes_used, #build_result, call, #logger

Methods included from Service::Initializer

#initialize

Class Method Details

.refresh_stream_name(can_manage:) ⇒ String

Builds the content-free refresh stream for one permission tier.

Parameters:

  • can_manage (Boolean)

    whether the subscriber can manage phone status

Returns:

  • (String)

    tier-scoped refresh stream name



34
35
36
37
# File 'app/services/employee_phone_status/broadcast_switchboard.rb', line 34

def self.refresh_stream_name(can_manage:)
  permission = can_manage ? :manage : :read
  "switchboard:#{permission}:refresh"
end

.stream_name(employee_id, can_manage:) ⇒ String

Builds the internal Action Cable stream for one watched employee and
permission tier.

Parameters:

  • employee_id (Integer)

    watched employee ID

  • can_manage (Boolean)

    whether the subscriber can manage phone status

Returns:

  • (String)

    scoped stream name



25
26
27
28
# File 'app/services/employee_phone_status/broadcast_switchboard.rb', line 25

def self.stream_name(employee_id, can_manage:)
  permission = can_manage ? :manage : :read
  "switchboard:#{permission}:employee:#{employee_id}"
end

Instance Method Details

#callvoid

This method returns an undefined value.

Broadcasts the requested card lifecycle operation.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/services/employee_phone_status/broadcast_switchboard.rb', line 42

def call
  return if employee_id.blank?

  case operation.to_sym
  when :update then broadcast_update
  when :replace then broadcast_replace
  when :remove then broadcast_remove
  when :refresh then broadcast_refresh
  else raise ArgumentError, "Unsupported switchboard operation: #{operation.inspect}"
  end
rescue StandardError => e
  ErrorReporting.warning(
    e,
    reason: ERROR_REASONS.fetch(operation.to_sym, 'switchboard_broadcast_failed'),
    party_id: employee_id
  )
end