relaxo 1.0.1 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/lib/relaxo.rb +26 -5
- data/lib/relaxo/changeset.rb +3 -3
- data/lib/relaxo/database.rb +30 -11
- data/lib/relaxo/dataset.rb +17 -5
- data/lib/relaxo/directory.rb +23 -6
- data/lib/relaxo/{schema.rb → logger.rb} +3 -27
- data/lib/relaxo/version.rb +2 -2
- metadata +93 -50
- data/.gitignore +0 -18
- data/.rspec +0 -3
- data/.simplecov +0 -9
- data/.travis.yml +0 -17
- data/Gemfile +0 -20
- data/README.md +0 -150
- data/Rakefile +0 -20
- data/bin/relaxo +0 -142
- data/bin/relaxo-admin +0 -61
- data/relaxo.gemspec +0 -30
- data/spec/relaxo/changeset_spec.rb +0 -39
- data/spec/relaxo/concurrency_spec.rb +0 -39
- data/spec/relaxo/database_spec.rb +0 -103
- data/spec/relaxo/enumeration_spec.rb +0 -30
- data/spec/relaxo/performance_spec.rb +0 -78
- data/spec/relaxo/test_records.rb +0 -25
data/relaxo.gemspec
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'relaxo/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "relaxo"
|
8
|
-
spec.version = Relaxo::VERSION
|
9
|
-
spec.authors = ["Samuel Williams"]
|
10
|
-
spec.email = ["samuel.williams@oriontransfer.co.nz"]
|
11
|
-
spec.description = <<-EOF
|
12
|
-
Relaxo provides a set of tools and interfaces for interacting with CouchDB.
|
13
|
-
It aims to be as simple and efficient as possible while still improving the
|
14
|
-
usability of various CouchDB features.
|
15
|
-
EOF
|
16
|
-
spec.summary = %q{Relaxo is a helper for loading and working with CouchDB.}
|
17
|
-
spec.homepage = ""
|
18
|
-
spec.license = "MIT"
|
19
|
-
|
20
|
-
spec.files = `git ls-files`.split($/)
|
21
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
22
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
23
|
-
spec.require_paths = ["lib"]
|
24
|
-
|
25
|
-
spec.add_dependency "rugged"
|
26
|
-
|
27
|
-
spec.add_development_dependency "rspec", "~> 3.4.0"
|
28
|
-
spec.add_development_dependency "bundler", "~> 1.3"
|
29
|
-
spec.add_development_dependency "rake"
|
30
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
|
2
|
-
require_relative 'test_records'
|
3
|
-
|
4
|
-
RSpec.describe Relaxo::Changeset do
|
5
|
-
include_context "test records"
|
6
|
-
|
7
|
-
it "should enumerate all documents including writes" do
|
8
|
-
records = []
|
9
|
-
|
10
|
-
database.commit(message: "Testing Enumeration") do |dataset|
|
11
|
-
5.times do |i|
|
12
|
-
object = dataset.append("extra-#{i}")
|
13
|
-
dataset.write("#{prefix}/extra-#{i}", object)
|
14
|
-
end
|
15
|
-
|
16
|
-
expect(dataset.exist?("#{prefix}/extra-0")).to be_truthy
|
17
|
-
|
18
|
-
records = dataset.each(prefix).to_a
|
19
|
-
end
|
20
|
-
|
21
|
-
expect(records.count).to be 25
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should enumerate all documents excluding deletes" do
|
25
|
-
records = []
|
26
|
-
|
27
|
-
database.commit(message: "Testing Enumeration") do |dataset|
|
28
|
-
5.times do |i|
|
29
|
-
dataset.delete("#{prefix}/#{i}")
|
30
|
-
end
|
31
|
-
|
32
|
-
expect(dataset.exist?("#{prefix}/0")).to be_falsey
|
33
|
-
|
34
|
-
records = dataset.each(prefix).to_a
|
35
|
-
end
|
36
|
-
|
37
|
-
expect(records.count).to be 15
|
38
|
-
end
|
39
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
|
2
|
-
require_relative 'test_records'
|
3
|
-
|
4
|
-
RSpec.describe Relaxo::Changeset do
|
5
|
-
include_context "test records"
|
6
|
-
|
7
|
-
it "should detect conflicts" do
|
8
|
-
events = []
|
9
|
-
|
10
|
-
alice = Fiber.new do
|
11
|
-
database.commit(message: "Alice Data") do |changeset|
|
12
|
-
events << :alice
|
13
|
-
|
14
|
-
object = changeset.append("sample-data-1")
|
15
|
-
changeset.write("conflict-path", object)
|
16
|
-
|
17
|
-
Fiber.yield
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
bob = Fiber.new do
|
22
|
-
database.commit(message: "Bob Data") do |changeset|
|
23
|
-
events << :bob
|
24
|
-
|
25
|
-
object = changeset.append("sample-data-1")
|
26
|
-
changeset.write("conflict-path", object)
|
27
|
-
|
28
|
-
Fiber.yield
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
alice.resume
|
33
|
-
bob.resume
|
34
|
-
alice.resume
|
35
|
-
bob.resume
|
36
|
-
|
37
|
-
expect(events).to be == [:alice, :bob, :bob]
|
38
|
-
end
|
39
|
-
end
|
@@ -1,103 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'relaxo'
|
3
|
-
|
4
|
-
RSpec.describe Relaxo::Database do
|
5
|
-
let(:database_path) {File.join(__dir__, 'test')}
|
6
|
-
|
7
|
-
let(:database) {Relaxo.connect(database_path, test_key: "test_value")}
|
8
|
-
|
9
|
-
let(:document_path) {'test/document.json'}
|
10
|
-
let(:sample_json) {'[1, 2, 3]'}
|
11
|
-
|
12
|
-
before(:each) {FileUtils.rm_rf(database_path)}
|
13
|
-
|
14
|
-
it "should be initially empty" do
|
15
|
-
expect(database).to be_empty
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should not be empty with one document" do
|
19
|
-
database.commit(message: "Create test document") do |dataset|
|
20
|
-
oid = dataset.append(sample_json)
|
21
|
-
dataset.write(document_path, oid)
|
22
|
-
end
|
23
|
-
|
24
|
-
expect(database).to_not be_empty
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should have metadata" do
|
28
|
-
expect(database[:test_key]).to be == "test_value"
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should create a document" do
|
32
|
-
database.commit(message: "Create test document") do |dataset|
|
33
|
-
oid = dataset.append(sample_json)
|
34
|
-
dataset.write(document_path, oid)
|
35
|
-
end
|
36
|
-
|
37
|
-
database.current do |dataset|
|
38
|
-
expect(dataset[document_path].data).to be == sample_json
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should erase a document" do
|
43
|
-
database.commit(message: "Create test document") do |dataset|
|
44
|
-
oid = dataset.append(sample_json)
|
45
|
-
dataset.write(document_path, oid)
|
46
|
-
end
|
47
|
-
|
48
|
-
database.commit(message: "Delete test document") do |dataset|
|
49
|
-
dataset.delete(document_path)
|
50
|
-
end
|
51
|
-
|
52
|
-
database.current do |dataset|
|
53
|
-
expect(dataset[document_path]).to be nil
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should create multiple documents" do
|
58
|
-
database.commit(message: "Create first document") do |dataset|
|
59
|
-
oid = dataset.append(sample_json)
|
60
|
-
dataset.write(document_path, oid)
|
61
|
-
end
|
62
|
-
|
63
|
-
database.commit(message: "Create second document") do |dataset|
|
64
|
-
oid = dataset.append(sample_json)
|
65
|
-
dataset.write(document_path + '2', oid)
|
66
|
-
end
|
67
|
-
|
68
|
-
database.current do |dataset|
|
69
|
-
expect(dataset[document_path].data).to be == sample_json
|
70
|
-
expect(dataset[document_path + '2'].data).to be == sample_json
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
it "can enumerate documents" do
|
75
|
-
database.commit(message: "Create first document") do |dataset|
|
76
|
-
oid = dataset.append(sample_json)
|
77
|
-
|
78
|
-
10.times do |id|
|
79
|
-
dataset.write(document_path + "-#{id}", oid)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
database.current do |dataset|
|
84
|
-
expect(dataset.each('test').count).to be == 10
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
it "can enumerate commit history of a document" do
|
89
|
-
10.times do |id|
|
90
|
-
database.commit(message: "revising the document #{id}") do |changeset|
|
91
|
-
oid = changeset.append("revision \##{id} of this document")
|
92
|
-
changeset.write('test/doot.txt', oid)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
database.commit(message: "unrelated commit") do |changeset|
|
97
|
-
oid = changeset.append("unrelated document")
|
98
|
-
changeset.write('test/unrelated.txt', oid)
|
99
|
-
end
|
100
|
-
|
101
|
-
expect(database.history('test/doot.txt').count).to be == 10
|
102
|
-
end
|
103
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
|
2
|
-
require_relative 'test_records'
|
3
|
-
|
4
|
-
RSpec.describe Relaxo::Dataset do
|
5
|
-
include_context "test records"
|
6
|
-
|
7
|
-
it "should enumerate all documents" do
|
8
|
-
records = []
|
9
|
-
|
10
|
-
database.current do |dataset|
|
11
|
-
records = dataset.each(prefix).to_a
|
12
|
-
end
|
13
|
-
|
14
|
-
expect(records.count).to be 20
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
RSpec.describe Relaxo::Changeset do
|
19
|
-
include_context "test records"
|
20
|
-
|
21
|
-
it "should enumerate all documents" do
|
22
|
-
records = []
|
23
|
-
|
24
|
-
database.commit(message: "Testing Enumeration") do |dataset|
|
25
|
-
records = dataset.each(prefix).to_a
|
26
|
-
end
|
27
|
-
|
28
|
-
expect(records.count).to be 20
|
29
|
-
end
|
30
|
-
end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'benchmark/ips' if ENV['BENCHMARK']
|
3
|
-
require 'ruby-prof' if ENV['PROFILE']
|
4
|
-
require 'flamegraph' if ENV['FLAMEGRAPH']
|
5
|
-
|
6
|
-
RSpec.describe "Relaxo Performance" do
|
7
|
-
let(:database_path) {File.join(__dir__, 'test')}
|
8
|
-
let(:database) {Relaxo.connect(database_path)}
|
9
|
-
|
10
|
-
if defined? Benchmark
|
11
|
-
def benchmark(name = nil)
|
12
|
-
Benchmark.ips do |benchmark|
|
13
|
-
# Collect more data for benchmark:
|
14
|
-
benchmark.time = 20
|
15
|
-
benchmark.warmup = 10
|
16
|
-
|
17
|
-
benchmark.report(name) do |i|
|
18
|
-
yield i
|
19
|
-
end
|
20
|
-
|
21
|
-
benchmark.compare!
|
22
|
-
end
|
23
|
-
end
|
24
|
-
elsif defined? RubyProf
|
25
|
-
def benchmark(name)
|
26
|
-
result = RubyProf.profile do
|
27
|
-
yield 1000
|
28
|
-
end
|
29
|
-
|
30
|
-
#result.eliminate_methods!([/^((?!Utopia).)*$/])
|
31
|
-
printer = RubyProf::FlatPrinter.new(result)
|
32
|
-
printer.print($stderr, min_percent: 1.0)
|
33
|
-
|
34
|
-
printer = RubyProf::GraphHtmlPrinter.new(result)
|
35
|
-
filename = name.gsub('/', '_') + '.html'
|
36
|
-
File.open(filename, "w") do |file|
|
37
|
-
printer.print(file)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
elsif defined? Flamegraph
|
41
|
-
def benchmark(name)
|
42
|
-
filename = name.gsub('/', '_') + '.html'
|
43
|
-
Flamegraph.generate(filename) do
|
44
|
-
yield 1
|
45
|
-
end
|
46
|
-
end
|
47
|
-
else
|
48
|
-
def benchmark(name)
|
49
|
-
yield 1
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
before(:each) do
|
54
|
-
FileUtils.rm_rf(database_path)
|
55
|
-
end
|
56
|
-
|
57
|
-
it "single transaction should be fast" do
|
58
|
-
benchmark("single") do |iterations|
|
59
|
-
database.commit(message: "Some Documents") do |dataset|
|
60
|
-
iterations.times do |i|
|
61
|
-
object = dataset.append("good-#{i}")
|
62
|
-
dataset.write("#{i%100}/#{i}", object)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
it "multiple transactions should be fast" do
|
69
|
-
benchmark("multiple") do |iterations|
|
70
|
-
iterations.times do |i|
|
71
|
-
database.commit(message: "Some Documents") do |dataset|
|
72
|
-
object = dataset.append("good-#{i}")
|
73
|
-
dataset.write("#{i%100}/#{i}", object)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
data/spec/relaxo/test_records.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'relaxo'
|
3
|
-
|
4
|
-
RSpec.shared_context "test records" do
|
5
|
-
let(:database_path) {File.join(__dir__, 'test')}
|
6
|
-
let(:database) {Relaxo.connect(database_path)}
|
7
|
-
|
8
|
-
let(:prefix) {"records"}
|
9
|
-
|
10
|
-
before(:each) do
|
11
|
-
FileUtils.rm_rf(database_path)
|
12
|
-
|
13
|
-
database.commit(message: "Create Sample Data") do |dataset|
|
14
|
-
20.times do |i|
|
15
|
-
object = dataset.append("good-#{i}")
|
16
|
-
dataset.write("#{prefix}/#{i}", object)
|
17
|
-
end
|
18
|
-
|
19
|
-
10.times do |i|
|
20
|
-
object = dataset.append("bad-#{i}")
|
21
|
-
dataset.write("#{prefix}/subdirectory/#{i}", object)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|