Class: EmployeePhoneStatus::BroadcastSwitchboard
- Inherits:
-
Object
- Object
- EmployeePhoneStatus::BroadcastSwitchboard
- 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
-
.refresh_stream_name(can_manage:) ⇒ String
Builds the content-free refresh stream for one permission tier.
-
.stream_name(employee_id, can_manage:) ⇒ String
Builds the internal Action Cable stream for one watched employee and permission tier.
Instance Method Summary collapse
-
#call ⇒ void
Broadcasts the requested card lifecycle operation.
Methods included from Service
#attributes_used, #build_result, call, #logger
Methods included from Service::Initializer
Class Method Details
.refresh_stream_name(can_manage:) ⇒ String
Builds the content-free refresh stream for one permission tier.
34 35 36 37 |
# File 'app/services/employee_phone_status/broadcast_switchboard.rb', line 34 def self.refresh_stream_name(can_manage:) = can_manage ? :manage : :read "switchboard:#{}:refresh" end |
.stream_name(employee_id, can_manage:) ⇒ String
Builds the internal Action Cable stream for one watched employee and
permission tier.
25 26 27 28 |
# File 'app/services/employee_phone_status/broadcast_switchboard.rb', line 25 def self.stream_name(employee_id, can_manage:) = can_manage ? :manage : :read "switchboard:#{}:employee:#{employee_id}" end |
Instance Method Details
#call ⇒ void
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 |