Class: GovFakeNotify::FetchFileCommand

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

Overview

A service used to fetch an attached file

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, attachment_store: AttachmentStore.instance) ⇒ FetchFileCommand

Returns a new instance of FetchFileCommand.



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

def initialize(id, attachment_store: AttachmentStore.instance)
  @id = id
  @attachment_store = attachment_store
  @errors = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



13
14
15
# File 'lib/gov_fake_notify/commands/fetch_file_command.rb', line 13

def errors
  @errors
end

#filenameObject (readonly)

Returns the value of attribute filename.



13
14
15
# File 'lib/gov_fake_notify/commands/fetch_file_command.rb', line 13

def filename
  @filename
end

Class Method Details

.call(id, **kwargs) ⇒ Object



15
16
17
# File 'lib/gov_fake_notify/commands/fetch_file_command.rb', line 15

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

Instance Method Details

#callObject



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

def call
  file_data = attachment_store.fetch(id)
  errors << 'File not found' and return if file_data.nil?

  @filename = file_data['file']
  self
end

#success?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/gov_fake_notify/commands/fetch_file_command.rb', line 33

def success?
  errors.empty?
end