class Rmk::Storage

Public Class Methods

new(file, iniobj) click to toggle source

create @param file [String] file path @param iniobj [Object] init inside obj

# File lib/rmk/storage.rb, line 7
def initialize(file, iniobj)
        @mutex = Thread::Mutex.new
        @file = file
        @data = File.exist?(@file) ? Rmk::Schedule.new_thread!{Marshal.load IO.binread @file} : iniobj
end

Public Instance Methods

data!() click to toggle source

get inside Hash obj without sync protected

# File lib/rmk/storage.rb, line 26
def data!; @data end
method_missing(name, *parms, &cmd) click to toggle source

redirect undef method to inside data obj with sync protected, often used for single operation

# File lib/rmk/storage.rb, line 29
def method_missing(name, *parms, &cmd) @mutex.synchronize{@data.send name, *parms, &cmd} end
save() click to toggle source

save data to disk file

# File lib/rmk/storage.rb, line 18
def save; @mutex.synchronize{IO.binwrite @file, Marshal.dump(@data)} end
sync(&cmd) click to toggle source

run block in mutex sync protected @yieldparam data [Hash] inside Hash obj @return [Object] block's result

# File lib/rmk/storage.rb, line 23
def sync(&cmd) @mutex.synchronize{cmd.call @data} end
wait_ready() click to toggle source

wait for storage ready to read and write @note before call this method storage is not ready, can't call any follow methods

# File lib/rmk/storage.rb, line 15
def wait_ready; @mutex.synchronize{@data = @data.value if Thread === @data} end