Class: Roma::KeyAccess
- Inherits:
-
Object
- Object
- Roma::KeyAccess
- Defined in:
- lib/roma/tools/key_access.rb
Instance Method Summary collapse
- #each_hash(path) ⇒ Object
-
#initialize(argv) ⇒ KeyAccess
constructor
A new instance of KeyAccess.
- #new_storage(ext) ⇒ Object
- #open_storage(path) ⇒ Object
- #options(argv) ⇒ Object
Constructor Details
#initialize(argv) ⇒ KeyAccess
Returns a new instance of KeyAccess.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/roma/tools/key_access.rb', line 14 def initialize(argv) (argv) each_hash(@path){|hname, dir| puts "hash : #{hname}" st = open_storage(dir) vn, last, clk, expt, value = st.get_raw2(@key) if vn if @sv puts "vnode: #{vn}" puts "last : #{Time.at(last)}" puts "clock: #{clk}" puts "expt : #{Time.at(expt)}" begin puts "value #{Marshal.load(value)}" rescue puts "value: #{value}" end else puts "exist" end st.closedb return end st.closedb } puts "not exist" end |
Instance Method Details
#each_hash(path) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/roma/tools/key_access.rb', line 61 def each_hash(path) Dir::glob("#{path}/*").each{|dir| next unless File::directory?(dir) hname = dir[dir.rindex('/')+1..-1] yield hname,dir } end |
#new_storage(ext) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/roma/tools/key_access.rb', line 88 def new_storage(ext) case(ext) when 'tc' return ::Roma::Storage::TCStorage.new when 'dbm' return Roma::Storage::DbmStorage.new when 'sql3' return Roma::Storage::SQLite3Storage.new else return nil end end |
#open_storage(path) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/roma/tools/key_access.rb', line 69 def open_storage(path) unless File::directory?(path) STDERR.puts "#{path} does not found." return nil end # get a file extension ext = File::extname(Dir::glob("#{path}/0.*")[0])[1..-1] # count a number of divided files divnum = Dir::glob("#{path}/*.#{ext}").length st = new_storage(ext) st.divnum = divnum st.vn_list = [] st.storage_path = path st.opendb st end |
#options(argv) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/roma/tools/key_access.rb', line 45 def (argv) opts = OptionParser.new opts.="usage:#{File.basename($0)} storage-path key" @sv = false opts.on("-v","--value","show value") { |v| @sv = true } opts.parse!(argv) raise OptionParser::ParseError.new if argv.length < 2 @path = argv[0] @key = argv[1] rescue OptionParser::ParseError => e STDERR.puts opts.help exit 1 end |