Class: RServiceBus2::SendAtStorageFile
- Inherits:
-
Object
- Object
- RServiceBus2::SendAtStorageFile
- Defined in:
- lib/rservicebus2/sendat_storage/file.rb
Overview
Send at storage file
Instance Method Summary collapse
- #add(msg) ⇒ Object
- #delete(idx) ⇒ Object
- #get_all ⇒ Object
-
#initialize(uri) ⇒ SendAtStorageFile
constructor
A new instance of SendAtStorageFile.
- #load(path) ⇒ Object
- #save ⇒ Object
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_all ⇒ Object
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 |
#save ⇒ Object
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 |