Class: RServiceBus::SendAtStorage_File

Inherits:
Object
  • Object
show all
Defined in:
lib/rservicebus/SendAtStorage/File.rb,
lib/rservicebus/SendAtStorage/InMemory.rb

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ SendAtStorage_File

Returns a new instance of SendAtStorage_File.



5
6
7
# File 'lib/rservicebus/SendAtStorage/File.rb', line 5

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

Instance Method Details

#Add(msg) ⇒ Object

Add



20
21
22
23
# File 'lib/rservicebus/SendAtStorage/File.rb', line 20

def Add( msg )
    @list << msg
    self.Save
end

#Delete(idx) ⇒ Object

Delete



31
32
33
34
# File 'lib/rservicebus/SendAtStorage/File.rb', line 31

def Delete( idx )
    @list.delete_at( idx )
    self.Save
end

#GetAllObject

GetAll



26
27
28
# File 'lib/rservicebus/SendAtStorage/File.rb', line 26

def GetAll
    return @list
end

#load(path) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/rservicebus/SendAtStorage/File.rb', line 8

def load( path )
    return Array.new unless File.exists?(path)

    content = IO.read( path )

    return Array.new if content == ''

    return YAML::load( content )
end

#SaveObject

Finish



37
38
39
40
# File 'lib/rservicebus/SendAtStorage/File.rb', line 37

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