Class: RServiceBus2::SendAtStorageFile

Inherits:
Object
  • Object
show all
Defined in:
lib/rservicebus2/sendat_storage/file.rb

Overview

Send at storage file

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ SendAtStorageFile

Returns a new instance of SendAtStorageFile.



4
5
6
# File 'lib/rservicebus2/sendat_storage/file.rb', line 4

def initialize(uri)
  @list = load(uri.path)
end

Instance Method Details

#add(msg) ⇒ Object



18
19
20
21
# File 'lib/rservicebus2/sendat_storage/file.rb', line 18

def add(msg)
  @list << msg
  save
end

#delete(idx) ⇒ Object



27
28
29
30
# File 'lib/rservicebus2/sendat_storage/file.rb', line 27

def delete(idx)
  @list.delete_at(idx)
  save
end

#get_allObject



23
24
25
# File 'lib/rservicebus2/sendat_storage/file.rb', line 23

def get_all
  @list
end

#load(path) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/rservicebus2/sendat_storage/file.rb', line 8

def load(path)
  return [] unless File.exist?(path)

  content = IO.read(path)

  return [] if content == ''

  YAML.load(content)
end

#saveObject



32
33
34
35
# File 'lib/rservicebus2/sendat_storage/file.rb', line 32

def save
  content = YAML.dump(@list)
  File.open(@uri.path, 'w') { |f| f.write(YAML.dump(content)) }
end