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
- #all ⇒ Object
- #delete(idx) ⇒ 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.
6 7 8 9 10 |
# File 'lib/rservicebus2/sendat_storage/file.rb', line 6 def initialize(uri) RServiceBus2.log "SendAtStorageFile configured: #{uri.path}" @list = load(uri.path) @path = uri.path end |
Instance Method Details
#add(msg) ⇒ Object
22 23 24 25 |
# File 'lib/rservicebus2/sendat_storage/file.rb', line 22 def add(msg) @list << msg save end |
#all ⇒ Object
27 28 29 |
# File 'lib/rservicebus2/sendat_storage/file.rb', line 27 def all @list end |
#delete(idx) ⇒ Object
31 32 33 34 |
# File 'lib/rservicebus2/sendat_storage/file.rb', line 31 def delete(idx) @list.delete_at(idx) save end |
#load(path) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/rservicebus2/sendat_storage/file.rb', line 12 def load(path) return [] unless File.exist?(path) content = IO.read(path) return [] if content == '' RServiceBus2.safe_load(content) end |
#save ⇒ Object
36 37 38 39 |
# File 'lib/rservicebus2/sendat_storage/file.rb', line 36 def save content = YAML.dump(@list) File.open(@path, 'w') { |f| f.write(content) } end |