rufus-cloche 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +6 -0
- data/Rakefile +81 -0
- data/lib/rufus/cloche.rb +2 -2
- data/test/bm/bm0.rb +66 -0
- data/test/ct_worker.rb +37 -0
- data/test/ct_writer.rb +21 -0
- data/test/test.rb +3 -0
- metadata +35 -12
data/CHANGELOG.txt
CHANGED
data/Rakefile
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rake'
|
4
|
+
|
5
|
+
|
6
|
+
load 'lib/rufus/cloche.rb'
|
7
|
+
|
8
|
+
|
9
|
+
#
|
10
|
+
# CLEAN
|
11
|
+
|
12
|
+
require 'rake/clean'
|
13
|
+
CLEAN.include('pkg', 'tmp', 'html')
|
14
|
+
task :default => [ :clean ]
|
15
|
+
|
16
|
+
|
17
|
+
#
|
18
|
+
# GEM
|
19
|
+
|
20
|
+
require 'jeweler'
|
21
|
+
|
22
|
+
Jeweler::Tasks.new do |gem|
|
23
|
+
|
24
|
+
gem.version = Rufus::Cloche::VERSION
|
25
|
+
gem.name = 'rufus-cloche'
|
26
|
+
gem.summary = 'a very stupid JSON hash store'
|
27
|
+
gem.description = %{
|
28
|
+
A very stupid JSON hash store.
|
29
|
+
|
30
|
+
It's built on top of yajl-ruby and File.lock. Defaults to 'json' (or 'json_pure') if yajl-ruby is not present (it's probably just a "gem install yajl-ruby" away.
|
31
|
+
|
32
|
+
Strives to be process-safe and thread-safe.
|
33
|
+
}
|
34
|
+
gem.email = 'jmettraux@gmail.com'
|
35
|
+
gem.homepage = 'http://github.com/jmettraux/rufus-cloche/'
|
36
|
+
gem.authors = [ 'John Mettraux' ]
|
37
|
+
gem.rubyforge_project = 'rufus'
|
38
|
+
|
39
|
+
gem.test_file = 'test/test.rb'
|
40
|
+
|
41
|
+
gem.add_dependency 'yajl-ruby'
|
42
|
+
gem.add_development_dependency "yard", ">= 0"
|
43
|
+
|
44
|
+
# gemspec spec : http://www.rubygems.org/read/chapter/20
|
45
|
+
end
|
46
|
+
Jeweler::GemcutterTasks.new
|
47
|
+
|
48
|
+
|
49
|
+
#
|
50
|
+
# DOC
|
51
|
+
|
52
|
+
begin
|
53
|
+
|
54
|
+
require 'yard'
|
55
|
+
|
56
|
+
YARD::Rake::YardocTask.new do |doc|
|
57
|
+
doc.options = [
|
58
|
+
'-o', 'html/rufus-cloche', '--title',
|
59
|
+
"rufus-cloche #{Rufus::Cloche::VERSION}"
|
60
|
+
]
|
61
|
+
end
|
62
|
+
|
63
|
+
rescue LoadError
|
64
|
+
|
65
|
+
task :yardoc do
|
66
|
+
abort "YARD is not available : sudo gem install yard"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
#
|
72
|
+
# TO THE WEB
|
73
|
+
|
74
|
+
task :upload_website => [ :clean, :rdoc ] do
|
75
|
+
|
76
|
+
account = 'jmettraux@rubyforge.org'
|
77
|
+
webdir = '/var/www/gforge-projects/rufus'
|
78
|
+
|
79
|
+
sh "rsync -azv -e ssh html/rufus-cloche #{account}:#{webdir}/"
|
80
|
+
end
|
81
|
+
|
data/lib/rufus/cloche.rb
CHANGED
@@ -57,7 +57,7 @@ module Rufus
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
VERSION = '0.1.
|
60
|
+
VERSION = '0.1.6'
|
61
61
|
|
62
62
|
attr_reader :dir
|
63
63
|
|
@@ -108,7 +108,7 @@ module Rufus
|
|
108
108
|
|
109
109
|
doc['_rev'] = doc['_rev'] + 1
|
110
110
|
|
111
|
-
File.open(file, 'wb') { |io| io.write(Cloche.json_encode(doc)) }
|
111
|
+
File.open(file.path, 'wb') { |io| io.write(Cloche.json_encode(doc)) }
|
112
112
|
end
|
113
113
|
|
114
114
|
nil
|
data/test/bm/bm0.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
|
2
|
+
$:.unshift('lib')
|
3
|
+
require 'benchmark'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'yajl'
|
6
|
+
require 'rufus/cloche'
|
7
|
+
|
8
|
+
N = 250
|
9
|
+
|
10
|
+
DOC = { '_id' => '0', 'type' => 'benchmark' }
|
11
|
+
1000.times { |i| DOC["key#{i}"] = { 'a' => 'b', 'c' => 'd', 'e' =>'f' } }
|
12
|
+
|
13
|
+
CLO = Rufus::Cloche.new(:dir => 'bm_cloche')
|
14
|
+
|
15
|
+
Benchmark.benchmark(' ' * 31 + Benchmark::Tms::CAPTION, 31) do |b|
|
16
|
+
|
17
|
+
b.report('marshal to file') do
|
18
|
+
N.times do
|
19
|
+
File.open('out.marshal', 'wb') { |f| f.write(Marshal.dump(DOC)) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
b.report('yajl to file') do
|
23
|
+
N.times do
|
24
|
+
File.open('out.json', 'wb') { |f| f.write(Yajl::Encoder.encode(DOC)) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
b.report('to cloche') do
|
28
|
+
N.times do |i|
|
29
|
+
DOC['_id'] = i.to_s
|
30
|
+
DOC['_rev'] = -1
|
31
|
+
CLO.put(DOC)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
puts
|
36
|
+
|
37
|
+
b.report('marshal from file') do
|
38
|
+
N.times do
|
39
|
+
doc = Marshal.load(File.read('out.marshal'))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
b.report('yajl from file') do
|
43
|
+
N.times do
|
44
|
+
doc = Yajl::Parser.parse(File.read('out.json'))
|
45
|
+
end
|
46
|
+
end
|
47
|
+
b.report('from cloche') do
|
48
|
+
N.times do |i|
|
49
|
+
doc = CLO.get('benchmark', i.to_s)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
#puts
|
54
|
+
#require 'json'
|
55
|
+
#b.report('json to file') do
|
56
|
+
# N.times do
|
57
|
+
# File.open('out.json', 'wb') { |f| f.write(DOC.to_json) }
|
58
|
+
# end
|
59
|
+
#end
|
60
|
+
#b.report('json from file') do
|
61
|
+
# N.times do
|
62
|
+
# doc = ::JSON.parse(File.read('out.json'))
|
63
|
+
# end
|
64
|
+
#end
|
65
|
+
end
|
66
|
+
|
data/test/ct_worker.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
require 'rubygems'
|
3
|
+
require 'lib/rufus/cloche'
|
4
|
+
|
5
|
+
CLO = Rufus::Cloche.new(:dir => 'cloche')
|
6
|
+
|
7
|
+
p $$
|
8
|
+
|
9
|
+
def process (task)
|
10
|
+
puts "#{$$} . processing task #{task['_id']}"
|
11
|
+
r = CLO.delete(task)
|
12
|
+
if r
|
13
|
+
puts "#{$$} x could not process task #{task['_id']} ===================="
|
14
|
+
else
|
15
|
+
icon = task['_id'].match(/^#{$$}:/) ? 'o' : 'O'
|
16
|
+
puts "#{$$} #{icon} processed task #{task['_id']}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
loop do
|
21
|
+
|
22
|
+
CLO.get_many('task').each { |task| process(task) }
|
23
|
+
|
24
|
+
(rand * 12).to_i.times do |i|
|
25
|
+
nt = {
|
26
|
+
'_id' => "#{$$}:#{i}:#{(Time.now.to_f * 1000).to_i}",
|
27
|
+
'type' => 'task'
|
28
|
+
}
|
29
|
+
t = CLO.put(nt)
|
30
|
+
if t
|
31
|
+
puts "#{$$} x new task #{nt['_id']} (failed)"
|
32
|
+
else
|
33
|
+
puts "#{$$} . new task #{nt['_id']}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
data/test/ct_writer.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
require 'rubygems'
|
3
|
+
require 'lib/rufus/cloche'
|
4
|
+
|
5
|
+
CLO = Rufus::Cloche.new(:dir => 'cloche')
|
6
|
+
|
7
|
+
p $$
|
8
|
+
|
9
|
+
100.times do
|
10
|
+
doc = CLO.get('person', 'john')
|
11
|
+
sleep rand
|
12
|
+
doc['pid'] = $$.to_s
|
13
|
+
d = CLO.put(doc)
|
14
|
+
puts d ? '* failure' : '. success'
|
15
|
+
if d
|
16
|
+
d['pid'] = $$.to_s
|
17
|
+
d = CLO.put(d)
|
18
|
+
puts d ? ' re_failure' : ' re_success'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
data/test/test.rb
CHANGED
@@ -5,11 +5,14 @@
|
|
5
5
|
# Fri Nov 13 09:09:58 JST 2009
|
6
6
|
#
|
7
7
|
|
8
|
+
require 'rubygems'
|
9
|
+
|
8
10
|
ROOT = File.join(File.dirname(__FILE__), '..')
|
9
11
|
|
10
12
|
require 'test/unit'
|
11
13
|
require File.join(ROOT, %w[ lib rufus cloche.rb ])
|
12
14
|
|
15
|
+
|
13
16
|
class ClocheTest < Test::Unit::TestCase
|
14
17
|
|
15
18
|
def setup
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rufus-cloche
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Mettraux
|
@@ -9,10 +9,29 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-16 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: yajl-ruby
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: yard
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
16
35
|
description: "\n\
|
17
36
|
A very stupid JSON hash store.\n\n\
|
18
37
|
It's built on top of yajl-ruby and File.lock. Defaults to 'json' (or 'json_pure') if yajl-ruby is not present (it's probably just a \"gem install yajl-ruby\" away.\n\n\
|
@@ -23,24 +42,28 @@ executables: []
|
|
23
42
|
extensions: []
|
24
43
|
|
25
44
|
extra_rdoc_files:
|
45
|
+
- LICENSE.txt
|
26
46
|
- README.rdoc
|
27
|
-
- CHANGELOG.txt
|
28
|
-
- CREDITS.txt
|
29
47
|
files:
|
30
|
-
- lib/rufus/cloche.rb
|
31
|
-
- lib/rufus-cloche.rb
|
32
48
|
- CHANGELOG.txt
|
33
49
|
- CREDITS.txt
|
34
50
|
- LICENSE.txt
|
35
|
-
- TODO.txt
|
36
51
|
- README.rdoc
|
37
|
-
|
52
|
+
- Rakefile
|
53
|
+
- TODO.txt
|
54
|
+
- lib/rufus-cloche.rb
|
55
|
+
- lib/rufus/cloche.rb
|
56
|
+
- test/bm/bm0.rb
|
57
|
+
- test/ct_worker.rb
|
58
|
+
- test/ct_writer.rb
|
59
|
+
- test/test.rb
|
60
|
+
has_rdoc: true
|
38
61
|
homepage: http://github.com/jmettraux/rufus-cloche/
|
39
62
|
licenses: []
|
40
63
|
|
41
64
|
post_install_message:
|
42
|
-
rdoc_options:
|
43
|
-
|
65
|
+
rdoc_options:
|
66
|
+
- --charset=UTF-8
|
44
67
|
require_paths:
|
45
68
|
- lib
|
46
69
|
required_ruby_version: !ruby/object:Gem::Requirement
|