Class: GovFakeNotify::FetchAllMessagesStatusCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/gov_fake_notify/commands/fetch_all_messages_status_command.rb

Overview

A service used to fetch all message statuses

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, store: Store.instance) ⇒ FetchAllMessagesStatusCommand

Returns a new instance of FetchAllMessagesStatusCommand.



18
19
20
21
22
23
# File 'lib/gov_fake_notify/commands/fetch_all_messages_status_command.rb', line 18

def initialize(params, store: Store.instance)
  @params = params
  @store = store
  @errors = []
  @messages = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



12
13
14
# File 'lib/gov_fake_notify/commands/fetch_all_messages_status_command.rb', line 12

def errors
  @errors
end

Class Method Details

.call(params, **kwargs) ⇒ Object



14
15
16
# File 'lib/gov_fake_notify/commands/fetch_all_messages_status_command.rb', line 14

def self.call(params, **kwargs)
  new(params, **kwargs).call
end

Instance Method Details

#callObject



25
26
27
28
29
30
# File 'lib/gov_fake_notify/commands/fetch_all_messages_status_command.rb', line 25

def call
  message_keys = store.transaction { store.roots.select { |k| k =~ /^message-/ } }
  @messages = store.transaction { message_keys.map { |key| store.fetch(key) } }

  self
end

#success?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/gov_fake_notify/commands/fetch_all_messages_status_command.rb', line 32

def success?
  errors.empty?
end

#to_jsonObject



36
37
38
39
# File 'lib/gov_fake_notify/commands/fetch_all_messages_status_command.rb', line 36

def to_json
  # We do not support links yet
  JSON.pretty_generate(notifications: messages, links: [])
end