pgldb 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/bin/pgldb CHANGED
@@ -1,13 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'gli'
3
- begin # XXX: Remove this begin/rescue before distributing your app
4
3
  require 'pgldb'
5
- rescue LoadError
6
- STDERR.puts "In development, you need to use `bundle exec bin/pgldb` to run your app"
7
- STDERR.puts "At install-time, RubyGems will make sure lib, etc. are in the load path"
8
- STDERR.puts "Feel free to remove this message from bin/pgldb now"
9
- exit 64
10
- end
11
4
 
12
5
  include GLI::App
13
6
 
@@ -33,13 +26,31 @@ command :start do |c|
33
26
  c.default_value 'default'
34
27
  c.flag :f
35
28
  c.action do |global_options,options,args|
29
+ puts 'nothting to do'
30
+ end
31
+ end
32
+
33
+ desc 'Describe start here'
34
+ arg_name 'Describe arguments to start here'
35
+ command :dump do |c|
36
+ c.desc 'Describe a switch to start'
37
+ c.switch :s
38
+
39
+ c.desc 'Describe a flag to start'
40
+ c.default_value 'default'
41
+ c.flag :f
42
+ c.action do |global_options,options,args|
43
+ raise 'pgldb dump db-dir [row count] [key byte] [value byte]' unless args[0]
44
+ ldb = LdbEngin.new(args[0])
36
45
 
37
- # Your command logic here
38
-
39
- # If you have any errors, just raise them
40
- # raise "that command made no sense"
46
+ rowcount = 1000
47
+ keybyte = 16
48
+ valuebyte = 100
49
+ rowcount = args[1].to_i if args[1]
50
+ keybyte = args[2].to_i if args[2]
51
+ valuebyte = args[3].to_i if args[3]
41
52
 
42
- puts "start command ran"
53
+ ldb.dump rowcount, keybyte, valuebyte
43
54
  end
44
55
  end
45
56
 
@@ -61,7 +72,9 @@ end
61
72
  on_error do |exception|
62
73
  # Error logic here
63
74
  # return false to skip default error handling
64
- true
75
+ puts exception.message
76
+ puts exception.backtrace
77
+ false
65
78
  end
66
79
 
67
80
  exit run(ARGV)
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'leveldb'
4
+
5
+ class LdbEngin
6
+ def initialize(dbdir)
7
+ @db = LevelDB::DB.new dbdir
8
+ end
9
+
10
+ def dump(rowcount, keybyte, valuebyte)
11
+ raise "keybyte(#{keybyte}) is too small for #{rowcount} rows." if rowcount.to_s.length > keybyte
12
+
13
+
14
+ puts "dump level-db with #{rowcount} rows. key = #{keybyte} bytes, value = #{valuebyte} bytes."
15
+ tstart = Time.new
16
+ (0..rowcount).each do |id|
17
+ key = id.to_s.rjust(keybyte, '0')
18
+ value = id.to_s.rjust(valuebyte, '-')
19
+ @db[key] = value
20
+ end
21
+ puts "dump finished. #{Time.new - tstart} seconds elapsed."
22
+
23
+ end
24
+ end
@@ -2,3 +2,5 @@ require 'pgldb/version.rb'
2
2
 
3
3
  # Add requires for other files you add to your project here, so
4
4
  # you just need to require this one file in your bin file
5
+
6
+ require 'ldb_engin'
@@ -1,3 +1,3 @@
1
1
  module Pgldb
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pgldb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -87,6 +87,7 @@ files:
87
87
  - bin/pgldb
88
88
  - lib/pgldb/version.rb
89
89
  - lib/pgldb.rb
90
+ - lib/ldb_engin.rb
90
91
  - README.rdoc
91
92
  - pgldb.rdoc
92
93
  homepage: http://your.website.com
@@ -109,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
110
  version: '0'
110
111
  segments:
111
112
  - 0
112
- hash: 3074989005385548258
113
+ hash: 892945757456173270
113
114
  required_rubygems_version: !ruby/object:Gem::Requirement
114
115
  none: false
115
116
  requirements:
@@ -118,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
119
  version: '0'
119
120
  segments:
120
121
  - 0
121
- hash: 3074989005385548258
122
+ hash: 892945757456173270
122
123
  requirements: []
123
124
  rubyforge_project:
124
125
  rubygems_version: 1.8.25