zdzolton-cambric 0.4.0 → 0.5.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.
- data/README.rdoc +31 -36
- data/VERSION +1 -1
- data/cambric.gemspec +5 -5
- data/lib/cambric.rb +22 -9
- data/spec/cambric_spec.rb +132 -24
- data/spec/spec.opts +6 -0
- metadata +5 -4
data/README.rdoc
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
= Cambric
|
2
2
|
|
3
|
-
|
3
|
+
Mildly opinionated management and usage of CouchDB from your Ruby apps.
|
4
|
+
|
5
|
+
Cambric supports applications that wish to use multiple CouchDB
|
6
|
+
databases/hosts, in a manner that wont muck up your application code.
|
7
|
+
Moreover, it encourages you to use one design document per database used
|
8
|
+
by the application.
|
4
9
|
|
5
10
|
(BTW, there's nothing specific to Rails in how this works.)
|
6
11
|
|
@@ -25,46 +30,36 @@ Opinionated management and usage of CouchDB from your Ruby apps.
|
|
25
30
|
}
|
26
31
|
}
|
27
32
|
end
|
28
|
-
|
29
|
-
# Optionally:
|
30
|
-
# Cambric.create_all_databases
|
31
33
|
|
32
|
-
2)
|
34
|
+
2) Use one of the following methods:
|
35
|
+
|
36
|
+
Cambric.prepare_database # Creates databases for the configured environment
|
37
|
+
# and pushes up their design docs.
|
38
|
+
|
39
|
+
Cambric.prepare_database! # Or, the bang method forcibly recreates your
|
40
|
+
# databases for the configured environment.
|
41
|
+
|
42
|
+
3) Interact with CouchRest::Database instances:
|
43
|
+
|
44
|
+
tweet_db = Cambric[:tweets]
|
33
45
|
|
34
46
|
# Just like normal...
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
47
|
+
tweet_db.save_doc :author => 'marbles',
|
48
|
+
:message => 'Is this pork or beef, @Randy?',
|
49
|
+
:followers => ['randy','zdzolton','trevorturk'],
|
50
|
+
:created_at => Time.now
|
39
51
|
|
40
52
|
# Except, you do NOT need to re-specify the design doc name when
|
41
|
-
# calling CouchRest::Database#view —
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
config.design_doc_name = 'twitter-clone'
|
52
|
-
config.environment = ENV['RAILS_ENV']
|
53
|
-
|
54
|
-
config.databases = {
|
55
|
-
:users => {
|
56
|
-
:development => 'http://127.0.0.1:5984/users-development',
|
57
|
-
:test => 'http://127.0.0.1:5984/users-test',
|
58
|
-
:production => 'http://prod.server:5984/users'
|
59
|
-
},
|
60
|
-
:tweets => {
|
61
|
-
:development => 'http://127.0.0.1:5984/tweets-development',
|
62
|
-
:test => 'http://127.0.0.1:5984/tweets-test',
|
63
|
-
:production => 'http://prod.server:5984/tweets'
|
64
|
-
}
|
65
|
-
}
|
66
|
-
end
|
67
|
-
irb> Cambric.push_all_design_docs
|
53
|
+
# calling CouchRest::Database#view —since you're only using one!
|
54
|
+
tweet_db.view 'by_follower_and_created_at', :limit => 1
|
55
|
+
|
56
|
+
4) Push view/design doc changes to CouchDB:
|
57
|
+
|
58
|
+
Cambric.push_design_docs
|
59
|
+
|
60
|
+
# Alternatively, you can just call this, since it wont create
|
61
|
+
# your database, if they already exist:
|
62
|
+
Cambric.prepare_database
|
68
63
|
|
69
64
|
== Installation
|
70
65
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/cambric.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{cambric}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.5.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Zachary Zolton", "Geoff Buesing"]
|
9
|
-
s.date = %q{2009-05-
|
9
|
+
s.date = %q{2009-05-29}
|
10
10
|
s.email = %q{zachary.zolton@gmail.com}
|
11
11
|
s.extra_rdoc_files = [
|
12
12
|
"LICENSE",
|
@@ -23,13 +23,13 @@ Gem::Specification.new do |s|
|
|
23
23
|
"lib/cambric.rb",
|
24
24
|
"spec/cambric_spec.rb",
|
25
25
|
"spec/fixtures/twitter-clone/tweets/views/by_follower_and_created_at/map.js",
|
26
|
+
"spec/spec.opts",
|
26
27
|
"spec/spec_helper.rb"
|
27
28
|
]
|
28
|
-
s.has_rdoc = true
|
29
29
|
s.homepage = %q{http://github.com/zdzolton/cambric}
|
30
30
|
s.rdoc_options = ["--charset=UTF-8"]
|
31
31
|
s.require_paths = ["lib"]
|
32
|
-
s.rubygems_version = %q{1.3.
|
32
|
+
s.rubygems_version = %q{1.3.3}
|
33
33
|
s.summary = %q{Opinionated management and usage of CouchDB from your Ruby apps.}
|
34
34
|
s.test_files = [
|
35
35
|
"spec/cambric_spec.rb",
|
@@ -38,7 +38,7 @@ Gem::Specification.new do |s|
|
|
38
38
|
|
39
39
|
if s.respond_to? :specification_version then
|
40
40
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
41
|
-
s.specification_version =
|
41
|
+
s.specification_version = 3
|
42
42
|
|
43
43
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
44
44
|
s.add_runtime_dependency(%q<jchris-couchrest>, [">= 0"])
|
data/lib/cambric.rb
CHANGED
@@ -24,32 +24,45 @@ module Cambric
|
|
24
24
|
@environment = config.environment
|
25
25
|
end
|
26
26
|
|
27
|
-
def self.
|
27
|
+
def self.create_databases!
|
28
28
|
@databases.each_pair do |name,db|
|
29
|
-
name_with_env = "#{name}-#{@environment}"
|
30
29
|
begin
|
31
|
-
db.server.create_db
|
30
|
+
db.server.create_db db.name
|
32
31
|
rescue
|
33
|
-
db.server.database(
|
32
|
+
db.server.database(db.name).recreate!
|
34
33
|
end
|
35
34
|
end
|
36
|
-
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.create_databases
|
38
|
+
@databases.each_pair{ |name,db| db.server.create_db db.name rescue nil }
|
37
39
|
end
|
38
40
|
|
39
41
|
def self.[](database)
|
40
42
|
@databases[database.to_sym]
|
41
43
|
end
|
42
44
|
|
43
|
-
def self.
|
45
|
+
def self.push_design_docs
|
44
46
|
@databases.keys.each{ |db| push_design_doc_for db.to_s }
|
45
47
|
end
|
48
|
+
|
49
|
+
def self.prepare_databases
|
50
|
+
create_databases
|
51
|
+
push_design_docs
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.prepare_databases!
|
55
|
+
create_databases!
|
56
|
+
push_design_docs
|
57
|
+
end
|
46
58
|
|
47
59
|
private
|
48
60
|
|
49
61
|
def self.push_design_doc_for database
|
50
62
|
design_doc_path = File.join @db_dir, database
|
51
|
-
|
52
|
-
|
63
|
+
if File.exist?(design_doc_path)
|
64
|
+
`couchapp push #{design_doc_path} #{@design_doc_name} #{self[database].uri}`
|
65
|
+
end
|
53
66
|
end
|
54
67
|
|
55
68
|
end
|
@@ -60,7 +73,7 @@ class Cambric::Configurator
|
|
60
73
|
|
61
74
|
def initialize
|
62
75
|
@design_doc_name = 'cambric'
|
63
|
-
@db_dir = '
|
76
|
+
@db_dir = 'cambric'
|
64
77
|
@environment = 'development'
|
65
78
|
@databases = {}
|
66
79
|
end
|
data/spec/cambric_spec.rb
CHANGED
@@ -4,14 +4,27 @@ require 'uri'
|
|
4
4
|
TWITTER_CLONE_DATABASES = {
|
5
5
|
:users => {
|
6
6
|
:development => 'http://127.0.0.1:5984/users-development',
|
7
|
-
:test => 'http://127.0.0.1:5984/users-
|
7
|
+
:test => 'http://127.0.0.1:5984/users-testing'
|
8
8
|
},
|
9
9
|
:tweets => {
|
10
10
|
:development => 'http://127.0.0.1:5984/tweets-development',
|
11
|
-
:test => 'http://127.0.0.1:5984/tweets-
|
11
|
+
:test => 'http://127.0.0.1:5984/tweets-testing'
|
12
12
|
}
|
13
13
|
}
|
14
14
|
|
15
|
+
def configure_twitter_clone
|
16
|
+
Cambric.configure do |config|
|
17
|
+
config.design_doc_name = 'twitter-clone'
|
18
|
+
config.db_dir = 'spec/fixtures/twitter-clone'
|
19
|
+
config.environment = 'test'
|
20
|
+
config.databases = TWITTER_CLONE_DATABASES
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete_twitter_clone_databases
|
25
|
+
%w(users tweets).each{ |db| Cambric[db].delete! rescue nil }
|
26
|
+
end
|
27
|
+
|
15
28
|
describe Cambric do
|
16
29
|
|
17
30
|
describe "after configuring without a block" do
|
@@ -23,8 +36,8 @@ describe Cambric do
|
|
23
36
|
Cambric.design_doc_name.should == 'cambric'
|
24
37
|
end
|
25
38
|
|
26
|
-
it "should default to '
|
27
|
-
Cambric.db_dir.should == '
|
39
|
+
it "should default to 'cambric' for the database directory" do
|
40
|
+
Cambric.db_dir.should == 'cambric'
|
28
41
|
end
|
29
42
|
|
30
43
|
it "should default to 'development' for the environment" do
|
@@ -32,7 +45,7 @@ describe Cambric do
|
|
32
45
|
end
|
33
46
|
|
34
47
|
it "should not throw a fit when creating databases" do
|
35
|
-
Cambric.
|
48
|
+
Cambric.create_databases
|
36
49
|
end
|
37
50
|
end
|
38
51
|
|
@@ -40,7 +53,7 @@ describe Cambric do
|
|
40
53
|
before :all do
|
41
54
|
Cambric.configure do |config|
|
42
55
|
config.design_doc_name = 'twitter-clone'
|
43
|
-
config.db_dir = '
|
56
|
+
config.db_dir = 'does/not/exist'
|
44
57
|
config.environment = 'test'
|
45
58
|
config.databases = TWITTER_CLONE_DATABASES
|
46
59
|
end
|
@@ -51,28 +64,25 @@ describe Cambric do
|
|
51
64
|
end
|
52
65
|
|
53
66
|
it "should have the config object's value for the database directory" do
|
54
|
-
Cambric.db_dir.should == '
|
67
|
+
Cambric.db_dir.should == 'does/not/exist'
|
55
68
|
end
|
56
69
|
|
57
70
|
it "should have the config object's value for the environment" do
|
58
71
|
Cambric.environment.should == 'test'
|
59
|
-
end
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should not blow up when calling push_design_docs for non-existent directories" do
|
75
|
+
Cambric.push_design_docs
|
76
|
+
end
|
60
77
|
end
|
61
78
|
|
62
79
|
describe "after creating databases" do
|
63
80
|
before :all do
|
64
|
-
|
65
|
-
|
66
|
-
config.db_dir = './spec/fixtures/twitter-clone'
|
67
|
-
config.environment = 'test'
|
68
|
-
config.databases = TWITTER_CLONE_DATABASES
|
69
|
-
end
|
70
|
-
Cambric.create_all_databases
|
81
|
+
configure_twitter_clone
|
82
|
+
Cambric.create_databases
|
71
83
|
end
|
72
84
|
|
73
|
-
after
|
74
|
-
%w(users tweets).each{ |db| Cambric[db].delete! }
|
75
|
-
end
|
85
|
+
after(:all){ delete_twitter_clone_databases }
|
76
86
|
|
77
87
|
it "should be able to query database info" do
|
78
88
|
%w(users tweets).each do |db|
|
@@ -82,25 +92,123 @@ describe Cambric do
|
|
82
92
|
|
83
93
|
it "should have the expected URLs" do
|
84
94
|
%w(users tweets).each do |db|
|
85
|
-
Cambric[db].uri.should == "http://127.0.0.1:5984/#{db}-
|
95
|
+
Cambric[db].uri.should == "http://127.0.0.1:5984/#{db}-testing"
|
86
96
|
end
|
87
97
|
end
|
88
98
|
|
89
|
-
it "should have the
|
99
|
+
it "should have not yet pushed the design docs" do
|
90
100
|
%w(users tweets).each do |db|
|
91
|
-
|
101
|
+
lambda do
|
102
|
+
Cambric[db].get("_design/twitter-clone")
|
103
|
+
end.should raise_error(RestClient::ResourceNotFound)
|
92
104
|
end
|
93
105
|
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "after pushing a test doc" do
|
109
|
+
before :all do
|
110
|
+
configure_twitter_clone
|
111
|
+
Cambric.create_databases
|
112
|
+
@test_doc = { 'foo' => 'bar' }
|
113
|
+
Cambric[:tweets].save_doc @test_doc
|
114
|
+
end
|
115
|
+
|
116
|
+
after(:all){ delete_twitter_clone_databases }
|
117
|
+
|
118
|
+
it "should not overwrite the database after calling create_databases" do
|
119
|
+
Cambric.create_databases
|
120
|
+
Cambric[:tweets].get(@test_doc['_id'])['foo'].should == 'bar'
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should overwrite the database after calling create_databases!" do
|
124
|
+
Cambric.create_databases!
|
125
|
+
lambda do
|
126
|
+
Cambric[:tweets].get(@test_doc['_id'])
|
127
|
+
end.should raise_error(RestClient::ResourceNotFound)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe "after pushing design docs" do
|
132
|
+
before :all do
|
133
|
+
configure_twitter_clone
|
134
|
+
Cambric.create_databases
|
135
|
+
Cambric.push_design_docs
|
136
|
+
end
|
137
|
+
|
138
|
+
after(:all){ delete_twitter_clone_databases }
|
94
139
|
|
95
140
|
it "should have defined views for design doc" do
|
96
141
|
design_doc = Cambric[:tweets].get("_design/twitter-clone")
|
97
142
|
design_doc['views']['by_follower_and_created_at'].should_not be_nil
|
98
143
|
end
|
99
|
-
|
144
|
+
|
100
145
|
it "should be able to query view without re-specifying design doc name" do
|
101
146
|
Cambric[:tweets].view 'by_follower_and_created_at'
|
102
147
|
end
|
103
148
|
end
|
149
|
+
|
150
|
+
describe "when the design doc already exists" do
|
151
|
+
before :all do
|
152
|
+
configure_twitter_clone
|
153
|
+
Cambric.create_databases
|
154
|
+
@design_doc = { '_id' => '_design/twitter-clone', 'foo' => 'bar' }
|
155
|
+
Cambric[:tweets].save_doc @design_doc
|
156
|
+
end
|
157
|
+
|
158
|
+
after(:all){ delete_twitter_clone_databases }
|
159
|
+
|
160
|
+
it "should overwrite when pushing design docs" do
|
161
|
+
Cambric.push_design_docs
|
162
|
+
Cambric[:tweets].get("_design/twitter-clone")['_rev'].should_not == @design_doc['_rev']
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe "after calling prepare_databases" do
|
167
|
+
before :all do
|
168
|
+
configure_twitter_clone
|
169
|
+
Cambric.prepare_databases
|
170
|
+
end
|
171
|
+
|
172
|
+
after(:all){ delete_twitter_clone_databases }
|
173
|
+
|
174
|
+
it "should have created both databases" do
|
175
|
+
%w(users tweets).each do |db|
|
176
|
+
Cambric[db].info.should_not be_nil
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should have pushed the design doc to both databases" do
|
181
|
+
%w(users tweets).each do |db|
|
182
|
+
Cambric[db].get('_design/twitter-clone').should_not be_nil
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
describe "calling prepare_databases again" do
|
187
|
+
before :all do
|
188
|
+
@test_doc = { 'eye' => 'ball' }
|
189
|
+
Cambric[:tweets].save_doc @test_doc
|
190
|
+
@design_doc_rev = Cambric[:tweets].get('_design/twitter-clone')['_rev']
|
191
|
+
Cambric.prepare_databases
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should not have re-created the database" do
|
195
|
+
Cambric[:tweets].get(@test_doc['_id'])['eye'].should == 'ball'
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should have updated the design doc" do
|
199
|
+
Cambric[:tweets].get('_design/twitter-clone')['_rev'].should_not == @design_doc_rev
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should re-create the database after calling prepare_databases!" do
|
204
|
+
test_doc = { 'bar' => 'bell' }
|
205
|
+
Cambric[:tweets].save_doc test_doc
|
206
|
+
Cambric.prepare_databases!
|
207
|
+
lambda do
|
208
|
+
Cambric[:tweets].get(test_doc['_id'])
|
209
|
+
end.should raise_error(RestClient::ResourceNotFound)
|
210
|
+
end
|
211
|
+
end
|
104
212
|
|
105
213
|
end
|
106
214
|
|
@@ -113,8 +221,8 @@ describe Cambric::Configurator do
|
|
113
221
|
@config.design_doc_name.should == 'cambric'
|
114
222
|
end
|
115
223
|
|
116
|
-
it "should default to '
|
117
|
-
@config.db_dir.should == '
|
224
|
+
it "should default to 'cambric' for the database directory" do
|
225
|
+
@config.db_dir.should == 'cambric'
|
118
226
|
end
|
119
227
|
|
120
228
|
it "should default to 'development' for the environment" do
|
data/spec/spec.opts
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zdzolton-cambric
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zachary Zolton
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-05-
|
13
|
+
date: 2009-05-29 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -43,8 +43,9 @@ files:
|
|
43
43
|
- lib/cambric.rb
|
44
44
|
- spec/cambric_spec.rb
|
45
45
|
- spec/fixtures/twitter-clone/tweets/views/by_follower_and_created_at/map.js
|
46
|
+
- spec/spec.opts
|
46
47
|
- spec/spec_helper.rb
|
47
|
-
has_rdoc:
|
48
|
+
has_rdoc: false
|
48
49
|
homepage: http://github.com/zdzolton/cambric
|
49
50
|
post_install_message:
|
50
51
|
rdoc_options:
|
@@ -68,7 +69,7 @@ requirements: []
|
|
68
69
|
rubyforge_project:
|
69
70
|
rubygems_version: 1.2.0
|
70
71
|
signing_key:
|
71
|
-
specification_version:
|
72
|
+
specification_version: 3
|
72
73
|
summary: Opinionated management and usage of CouchDB from your Ruby apps.
|
73
74
|
test_files:
|
74
75
|
- spec/cambric_spec.rb
|