Class: RServiceBus::StateStorage_Dir
- Inherits:
-
Object
- Object
- RServiceBus::StateStorage_Dir
- Defined in:
- lib/rservicebus/StateStorage/Dir.rb
Instance Method Summary collapse
-
#Begin ⇒ Object
Start.
-
#Commit ⇒ Object
Finish.
-
#Get(handler) ⇒ Object
Get.
-
#getPath(handler) ⇒ Object
Detail Functions.
-
#initialize(uri) ⇒ StateStorage_Dir
constructor
A new instance of StateStorage_Dir.
- #load(path) ⇒ Object
Constructor Details
#initialize(uri) ⇒ StateStorage_Dir
Returns a new instance of StateStorage_Dir.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rservicebus/StateStorage/Dir.rb', line 5 def initialize( uri ) @stateDir = uri.path inputDir = Dir.new( @stateDir ) unless File.writable?(@stateDir) then puts "***** Directory is not writable, #{@stateDir}." puts "***** Make the directory, #{@stateDir}, writable and try again." puts '***** Or, set the State Directory explicitly by, STATE_URI=<dir://path/to/state>' abort(); end rescue Errno::ENOENT => e puts "***** Directory does not exist, #{@stateDir}." puts "***** Create the directory, #{@stateDir}, and try again." puts "***** eg, mkdir #{@stateDir}" puts '***** Or, set the State Directory explicitly by, STATE_URI=<dir://path/to/state>' abort(); rescue Errno::ENOTDIR => e puts "***** The specified path does not point to a directory, #{@stateDir}." puts "***** Either repoint path to a directory, or remove, #{@stateDir}, and create it as a directory." puts "***** eg, rm #{@stateDir} && mkdir #{@stateDir}" puts '***** Or, set the State Directory explicitly by, STATE_URI=<dir://path/to/state>' abort(); end |
Instance Method Details
#Begin ⇒ Object
Start
30 31 32 |
# File 'lib/rservicebus/StateStorage/Dir.rb', line 30 def Begin @list = Array.new end |
#Commit ⇒ Object
Finish
44 45 46 47 48 |
# File 'lib/rservicebus/StateStorage/Dir.rb', line 44 def Commit @list.each do |e| File.open( e['path'], 'w') { |f| f.write( YAML::dump( e['hash'] ) ) } end end |
#Get(handler) ⇒ Object
Get
35 36 37 38 39 40 41 |
# File 'lib/rservicebus/StateStorage/Dir.rb', line 35 def Get( handler ) path = self.getPath( handler ) hash = self.load( path ) @list << Hash['path', path, 'hash', hash] return hash end |
#getPath(handler) ⇒ Object
Detail Functions
51 52 53 54 55 |
# File 'lib/rservicebus/StateStorage/Dir.rb', line 51 def getPath( handler ) path = "#{@stateDir}/#{handler.class.name}" return path end |
#load(path) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/rservicebus/StateStorage/Dir.rb', line 57 def load( path ) return Hash.new unless File.exists?(path) content = IO.read( path ) return Hash.new if content == '' return YAML::load( content ) end |