Class: GovFakeNotify::FetchMessageStatusCommand

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

Overview

A service used to fetch a message status

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, store: Store.instance) ⇒ FetchMessageStatusCommand

Returns a new instance of FetchMessageStatusCommand.



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

def initialize(id, store: Store.instance)
  @id = id
  @store = store
  @errors = []
  @message = nil
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



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

def errors
  @errors
end

Class Method Details

.call(id, **kwargs) ⇒ Object



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

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

Instance Method Details

#callObject



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

def call
  @message = store.transaction { store.fetch("message-#{id}") }
  errors << 'Message not found' and return if message.nil?

  self
end

#success?Boolean

Returns:

  • (Boolean)


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

def success?
  errors.empty?
end

#to_jsonObject



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

def to_json
  JSON.pretty_generate(message)
end