Class: CommandTower::Messaging::Planner::MessageOverrides

Inherits:
Data
  • Object
show all
Defined in:
app/services/command_tower/messaging/planner/message_overrides.rb

Constant Summary collapse

FORBIDDEN_KEYS =
%w[force_mandatory mandatory elevate_mandatory].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#channels_addObject (readonly)

Returns the value of attribute channels_add

Returns:

  • (Object)

    the current value of channels_add



6
7
8
# File 'app/services/command_tower/messaging/planner/message_overrides.rb', line 6

def channels_add
  @channels_add
end

#channels_removeObject (readonly)

Returns the value of attribute channels_remove

Returns:

  • (Object)

    the current value of channels_remove



6
7
8
# File 'app/services/command_tower/messaging/planner/message_overrides.rb', line 6

def channels_remove
  @channels_remove
end

#inboxObject (readonly)

Returns the value of attribute inbox

Returns:

  • (Object)

    the current value of inbox



6
7
8
# File 'app/services/command_tower/messaging/planner/message_overrides.rb', line 6

def inbox
  @inbox
end

Class Method Details

.normalize(raw) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/services/command_tower/messaging/planner/message_overrides.rb', line 9

def self.normalize(raw)
  return nil if raw.nil?

  unless raw.respond_to?(:to_h)
    raise IllegalOverrideError, "message_overrides must be a hash-like object"
  end

  hash = raw.to_h.transform_keys(&:to_s)

  FORBIDDEN_KEYS.each do |key|
    if hash.key?(key)
      raise IllegalOverrideError, "message_overrides cannot include #{key}"
    end
  end

  channels_add = Array(hash["channels_add"]).map(&:to_s).freeze
  channels_remove = Array(hash["channels_remove"]).map(&:to_s).freeze
  inbox = hash.key?("inbox") ? !!hash["inbox"] : nil

  new(channels_add:, channels_remove:, inbox:).freeze
end