eee-c-couch_design_docs 1.0.2 → 1.1.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/History.txt +14 -0
- data/README.txt +12 -6
- data/Rakefile +4 -1
- data/couch_design_docs.gemspec +14 -8
- data/fixtures/{a → _design/a}/b/c.js +0 -0
- data/fixtures/{a → _design/a}/b/d.js +0 -0
- data/fixtures/bar.json +1 -0
- data/fixtures/foo.json +1 -0
- data/lib/couch_design_docs.rb +28 -5
- data/lib/couch_design_docs/{directory.rb → design_directory.rb} +2 -4
- data/lib/couch_design_docs/document_directory.rb +19 -0
- data/lib/couch_design_docs/store.rb +3 -2
- data/spec/couch_design_docs_spec.rb +71 -12
- metadata +33 -9
data/History.txt
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
== 1.1.0 / 2009-07-31
|
2
|
+
|
3
|
+
* Add the ability to upload "normal" documents in addition to design
|
4
|
+
documents.
|
5
|
+
* <tt>CouchDesignDocs::upload_dir</tt> is aliased as
|
6
|
+
<tt>CouchDesignDocs::put_dir</tt> and is DEPRECATED.
|
7
|
+
* <tt>CouchDesignDocs::put_dir</tt> now puts both design documents
|
8
|
+
and "normal" documents onto the CouchDB database.
|
9
|
+
* <tt>CouchDesignDocs::put_design_dir</tt> has been added to put
|
10
|
+
design documents
|
11
|
+
* <tt>CouchDesignDocs::put_document_dir</tt> has been added to put
|
12
|
+
"normal" documents
|
13
|
+
|
14
|
+
|
1
15
|
== 1.0.2 / 2009-07-13
|
2
16
|
|
3
17
|
* Round out the API so that it is possible to load an entire directory
|
data/README.txt
CHANGED
@@ -4,24 +4,30 @@ couch_design_docs
|
|
4
4
|
|
5
5
|
== DESCRIPTION:
|
6
6
|
|
7
|
-
Manage CouchDB views.
|
7
|
+
Manage CouchDB views and documents.
|
8
8
|
|
9
9
|
== FEATURES/PROBLEMS:
|
10
10
|
|
11
|
-
*
|
12
|
-
|
11
|
+
* Store your CouchDB documents on the filesystem for on-demand
|
12
|
+
upload. Design documents are kept in a <tt>_design</tt>
|
13
|
+
sub-directory, with <tt>.js</tt> extensions. Normal documents are
|
14
|
+
stored with a <tt>.json</tt> extension.
|
13
15
|
|
14
16
|
== SYNOPSIS:
|
15
17
|
|
16
18
|
DB_URL = "http://localhost:5984/db"
|
17
|
-
DIRECTORY = "/repos/db/
|
19
|
+
DIRECTORY = "/repos/db/couchdb/"
|
18
20
|
|
19
|
-
# /repos/db/
|
21
|
+
# /repos/db/couchdb/_design/lucene/transform.js
|
22
|
+
# /repos/db/couchdb/foo.json
|
20
23
|
|
21
|
-
CouchDesignDocs.
|
24
|
+
CouchDesignDocs.put_dir(DB_URL, DIRECTORY)
|
22
25
|
|
23
26
|
# => lucene design document with a "transform" function containing
|
24
27
|
# the contents of transform.js
|
28
|
+
# - AND -
|
29
|
+
# a document named "foo" with the JSON contents from the foo.json
|
30
|
+
# file
|
25
31
|
|
26
32
|
== REQUIREMENTS:
|
27
33
|
|
data/Rakefile
CHANGED
data/couch_design_docs.gemspec
CHANGED
@@ -2,24 +2,24 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{couch_design_docs}
|
5
|
-
s.version = "1.0
|
5
|
+
s.version = "1.1.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Chris Strom"]
|
9
|
-
s.date = %q{2009-07-
|
9
|
+
s.date = %q{2009-07-31}
|
10
10
|
s.default_executable = %q{couch_design_docs}
|
11
|
-
s.description = %q{Manage CouchDB views.}
|
11
|
+
s.description = %q{Manage CouchDB views and documents.}
|
12
12
|
s.email = %q{chris@eeecooks.com}
|
13
13
|
s.executables = ["couch_design_docs"]
|
14
14
|
s.extra_rdoc_files = ["History.txt", "README.txt", "bin/couch_design_docs"]
|
15
|
-
s.files = ["History.txt", "README.txt", "Rakefile", "bin/couch_design_docs", "couch_design_docs.gemspec", "fixtures/a/b/c.js", "fixtures/a/b/d.js", "lib/couch_design_docs.rb", "lib/couch_design_docs/
|
15
|
+
s.files = ["History.txt", "README.txt", "Rakefile", "bin/couch_design_docs", "couch_design_docs.gemspec", "fixtures/_design/a/b/c.js", "fixtures/_design/a/b/d.js", "fixtures/bar.json", "fixtures/foo.json", "lib/couch_design_docs.rb", "lib/couch_design_docs/design_directory.rb", "lib/couch_design_docs/document_directory.rb", "lib/couch_design_docs/store.rb", "spec/couch_design_docs_spec.rb", "spec/spec_helper.rb", "test/test_couch_design_docs.rb"]
|
16
16
|
s.has_rdoc = true
|
17
17
|
s.homepage = %q{http://github.com/eee-c/couch_design_docs}
|
18
18
|
s.rdoc_options = ["--main", "README.txt"]
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
s.rubyforge_project = %q{couch_design_docs}
|
21
21
|
s.rubygems_version = %q{1.3.1}
|
22
|
-
s.summary = %q{Manage CouchDB views}
|
22
|
+
s.summary = %q{Manage CouchDB views and documents}
|
23
23
|
s.test_files = ["test/test_couch_design_docs.rb"]
|
24
24
|
|
25
25
|
if s.respond_to? :specification_version then
|
@@ -28,16 +28,22 @@ Gem::Specification.new do |s|
|
|
28
28
|
|
29
29
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
30
30
|
s.add_runtime_dependency(%q<json>, [">= 0"])
|
31
|
-
s.add_runtime_dependency(%q<
|
31
|
+
s.add_runtime_dependency(%q<rest-client>, [">= 0"])
|
32
|
+
s.add_runtime_dependency(%q<rest-client>, [">= 0.9.2"])
|
33
|
+
s.add_runtime_dependency(%q<json>, [">= 1.1.3"])
|
32
34
|
s.add_development_dependency(%q<bones>, [">= 2.5.1"])
|
33
35
|
else
|
34
36
|
s.add_dependency(%q<json>, [">= 0"])
|
35
|
-
s.add_dependency(%q<
|
37
|
+
s.add_dependency(%q<rest-client>, [">= 0"])
|
38
|
+
s.add_dependency(%q<rest-client>, [">= 0.9.2"])
|
39
|
+
s.add_dependency(%q<json>, [">= 1.1.3"])
|
36
40
|
s.add_dependency(%q<bones>, [">= 2.5.1"])
|
37
41
|
end
|
38
42
|
else
|
39
43
|
s.add_dependency(%q<json>, [">= 0"])
|
40
|
-
s.add_dependency(%q<
|
44
|
+
s.add_dependency(%q<rest-client>, [">= 0"])
|
45
|
+
s.add_dependency(%q<rest-client>, [">= 0.9.2"])
|
46
|
+
s.add_dependency(%q<json>, [">= 1.1.3"])
|
41
47
|
s.add_dependency(%q<bones>, [">= 2.5.1"])
|
42
48
|
end
|
43
49
|
end
|
File without changes
|
File without changes
|
data/fixtures/bar.json
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"bar":"2"}
|
data/fixtures/foo.json
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"foo":"1"}
|
data/lib/couch_design_docs.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
|
-
require 'pp'
|
2
|
-
|
3
1
|
module CouchDesignDocs
|
4
2
|
|
5
3
|
# :stopdoc:
|
6
|
-
VERSION = '1.0
|
4
|
+
VERSION = '1.1.0'
|
7
5
|
LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
|
8
6
|
PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
|
9
7
|
# :startdoc:
|
@@ -18,12 +16,37 @@ module CouchDesignDocs
|
|
18
16
|
# directory, <tt>dir</tt> containing design documents, creates
|
19
17
|
# design documents in the CouchDB database
|
20
18
|
#
|
19
|
+
def self.put_dir(db_uri, dir)
|
20
|
+
self.put_design_dir(db_uri, "#{dir}/_design")
|
21
|
+
self.put_document_dir(db_uri, dir)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Alias for <tt>put_dir</tt>
|
21
25
|
def self.upload_dir(db_uri, dir)
|
26
|
+
self.put_dir(db_uri, dir)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Upload design documents from <tt>dir</tt> to the CouchDB database
|
30
|
+
# located at <tt>db_uri</tt>
|
31
|
+
#
|
32
|
+
def self.put_design_dir(db_uri, dir)
|
22
33
|
store = Store.new(db_uri)
|
23
|
-
dir =
|
24
|
-
store.
|
34
|
+
dir = DesignDirectory.new(dir)
|
35
|
+
store.put_design_documents(dir.to_hash)
|
25
36
|
end
|
26
37
|
|
38
|
+
# Upload documents from <tt>dir</tt> to the CouchDB database
|
39
|
+
# located at <tt>db_uri</tt>
|
40
|
+
#
|
41
|
+
def self.put_document_dir(db_uri, dir)
|
42
|
+
store = Store.new(db_uri)
|
43
|
+
dir = DocumentDirectory.new(dir)
|
44
|
+
dir.each_document do |name, contents|
|
45
|
+
Store.put!("#{db_uri}/#{name}", contents)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
|
27
50
|
# Returns the library path for the module. If any arguments are given,
|
28
51
|
# they will be joined to the end of the libray path using
|
29
52
|
# <tt>File.join</tt>.
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'pp'
|
2
|
-
|
3
1
|
class Hash
|
4
2
|
def deep_merge(other)
|
5
3
|
self.merge(other) do |key, oldval, newval|
|
@@ -9,7 +7,7 @@ class Hash
|
|
9
7
|
end
|
10
8
|
|
11
9
|
module CouchDesignDocs
|
12
|
-
class
|
10
|
+
class DesignDirectory
|
13
11
|
|
14
12
|
attr_accessor :couch_view_dir
|
15
13
|
|
@@ -29,7 +27,7 @@ module CouchDesignDocs
|
|
29
27
|
|
30
28
|
def to_hash
|
31
29
|
Dir["#{couch_view_dir}/**/*.js"].inject({}) do |memo, filename|
|
32
|
-
|
30
|
+
DesignDirectory.
|
33
31
|
a_to_hash(expand_file(filename)).
|
34
32
|
deep_merge(memo)
|
35
33
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module CouchDesignDocs
|
2
|
+
class DocumentDirectory
|
3
|
+
|
4
|
+
attr_accessor :couch_doc_dir
|
5
|
+
|
6
|
+
def initialize(path)
|
7
|
+
Dir.new(path)
|
8
|
+
@couch_doc_dir = path
|
9
|
+
end
|
10
|
+
|
11
|
+
def each_document
|
12
|
+
Dir["#{couch_doc_dir}/*.json"].each do |filename|
|
13
|
+
yield [ File.basename(filename, '.json'),
|
14
|
+
JSON.parse(File.new(filename).read) ]
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'rubygems'
|
1
2
|
require 'restclient'
|
2
3
|
require 'json'
|
3
4
|
|
@@ -12,11 +13,11 @@ module CouchDesignDocs
|
|
12
13
|
@url = url
|
13
14
|
end
|
14
15
|
|
15
|
-
# Loads all supplied
|
16
|
+
# Loads all supplied design documents in the current store.
|
16
17
|
# Given a hash <tt>h</tt>, the keys being the CouchDB document
|
17
18
|
# name and values of design documents
|
18
19
|
#
|
19
|
-
def
|
20
|
+
def put_design_documents(h)
|
20
21
|
h.each_pair do |document_name, doc|
|
21
22
|
Store.put!("#{url}/_design/#{document_name}", doc)
|
22
23
|
end
|
@@ -1,19 +1,49 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), %w[spec_helper])
|
2
2
|
|
3
3
|
describe CouchDesignDocs do
|
4
|
+
it "should be able to load design and normal documents" do
|
5
|
+
CouchDesignDocs.
|
6
|
+
should_receive(:put_design_dir).
|
7
|
+
with("uri", "fixtures/_design")
|
8
|
+
|
9
|
+
CouchDesignDocs.
|
10
|
+
should_receive(:put_document_dir).
|
11
|
+
with("uri", "fixtures")
|
12
|
+
|
13
|
+
CouchDesignDocs.put_dir("uri", "fixtures")
|
14
|
+
end
|
15
|
+
|
4
16
|
it "should be able to load directory/JS files into CouchDB as design docs" do
|
5
17
|
store = mock("Store")
|
6
18
|
Store.stub!(:new).and_return(store)
|
7
19
|
|
8
|
-
dir = mock("Directory")
|
20
|
+
dir = mock("Design Directory")
|
9
21
|
dir.stub!(:to_hash).and_return({ "foo" => "bar" })
|
10
|
-
|
22
|
+
DesignDirectory.stub!(:new).and_return(dir)
|
11
23
|
|
12
24
|
store.
|
13
|
-
should_receive(:
|
25
|
+
should_receive(:put_design_documents).
|
14
26
|
with({ "foo" => "bar" })
|
15
27
|
|
16
|
-
CouchDesignDocs.
|
28
|
+
CouchDesignDocs.put_design_dir("uri", "fixtures")
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should be able to load documents into CouchDB" do
|
32
|
+
store = mock("Store")
|
33
|
+
Store.stub!(:new).and_return(store)
|
34
|
+
|
35
|
+
dir = mock("Document Directory")
|
36
|
+
dir.
|
37
|
+
stub!(:each_document).
|
38
|
+
and_yield('foo', {"foo" => "1"})
|
39
|
+
|
40
|
+
DocumentDirectory.stub!(:new).and_return(dir)
|
41
|
+
|
42
|
+
Store.
|
43
|
+
should_receive(:put!).
|
44
|
+
with('uri/foo', {"foo" => "1"})
|
45
|
+
|
46
|
+
CouchDesignDocs.put_document_dir("uri", "fixtures")
|
17
47
|
end
|
18
48
|
end
|
19
49
|
|
@@ -78,7 +108,7 @@ describe Store do
|
|
78
108
|
with("uri/_design/a",
|
79
109
|
'{"b":{"c":"function(doc) { return true; }"}}',
|
80
110
|
:content_type => 'application/json')
|
81
|
-
@it.
|
111
|
+
@it.put_design_documents(@hash)
|
82
112
|
end
|
83
113
|
|
84
114
|
it "should be able to retrieve an existing document" do
|
@@ -101,20 +131,49 @@ describe Store do
|
|
101
131
|
end
|
102
132
|
end
|
103
133
|
|
104
|
-
describe
|
134
|
+
describe DocumentDirectory do
|
135
|
+
it "should require a root directory for instantiation" do
|
136
|
+
lambda { DocumentDirectory.new }.
|
137
|
+
should raise_error
|
138
|
+
|
139
|
+
lambda { DocumentDirectory.new("foo") }.
|
140
|
+
should raise_error
|
141
|
+
|
142
|
+
lambda { DocumentDirectory.new("fixtures")}.
|
143
|
+
should_not raise_error
|
144
|
+
end
|
145
|
+
|
146
|
+
context "a valid directory" do
|
147
|
+
before(:each) do
|
148
|
+
@it = DocumentDirectory.new("fixtures")
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should be able to iterate over the documents" do
|
152
|
+
everything = []
|
153
|
+
@it.each_document do |name, contents|
|
154
|
+
everything << [name, contents]
|
155
|
+
end
|
156
|
+
everything.
|
157
|
+
should == [['bar', {"bar" => "2"}],
|
158
|
+
['foo', {"foo" => "1"}]]
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe DesignDirectory do
|
105
164
|
it "should require a root directory for instantiation" do
|
106
|
-
lambda {
|
165
|
+
lambda { DesignDirectory.new }.
|
107
166
|
should raise_error
|
108
167
|
|
109
|
-
lambda {
|
168
|
+
lambda { DesignDirectory.new("foo") }.
|
110
169
|
should raise_error
|
111
170
|
|
112
|
-
lambda {
|
171
|
+
lambda { DesignDirectory.new("fixtures/_design")}.
|
113
172
|
should_not raise_error
|
114
173
|
end
|
115
174
|
|
116
175
|
it "should convert arrays into deep hashes" do
|
117
|
-
|
176
|
+
DesignDirectory.
|
118
177
|
a_to_hash(%w{a b c d}).
|
119
178
|
should == {
|
120
179
|
'a' => {
|
@@ -127,11 +186,11 @@ describe Directory do
|
|
127
186
|
|
128
187
|
context "a valid directory" do
|
129
188
|
before(:each) do
|
130
|
-
@it =
|
189
|
+
@it = DesignDirectory.new("fixtures/_design")
|
131
190
|
end
|
132
191
|
|
133
192
|
it "should list dirs, basename and contents of a file" do
|
134
|
-
@it.expand_file("fixtures/a/b/c.js").
|
193
|
+
@it.expand_file("fixtures/_design/a/b/c.js").
|
135
194
|
should == ['a', 'b', 'c', 'function(doc) { return true; }']
|
136
195
|
end
|
137
196
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eee-c-couch_design_docs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Strom
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-07-
|
12
|
+
date: 2009-07-31 00:00:00 -07:00
|
13
13
|
default_executable: couch_design_docs
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -23,7 +23,7 @@ dependencies:
|
|
23
23
|
version: "0"
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
26
|
+
name: rest-client
|
27
27
|
type: :runtime
|
28
28
|
version_requirement:
|
29
29
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -32,6 +32,26 @@ dependencies:
|
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: "0"
|
34
34
|
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rest-client
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.9.2
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: json
|
47
|
+
type: :runtime
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.1.3
|
54
|
+
version:
|
35
55
|
- !ruby/object:Gem::Dependency
|
36
56
|
name: bones
|
37
57
|
type: :development
|
@@ -42,7 +62,7 @@ dependencies:
|
|
42
62
|
- !ruby/object:Gem::Version
|
43
63
|
version: 2.5.1
|
44
64
|
version:
|
45
|
-
description: Manage CouchDB views.
|
65
|
+
description: Manage CouchDB views and documents.
|
46
66
|
email: chris@eeecooks.com
|
47
67
|
executables:
|
48
68
|
- couch_design_docs
|
@@ -58,16 +78,20 @@ files:
|
|
58
78
|
- Rakefile
|
59
79
|
- bin/couch_design_docs
|
60
80
|
- couch_design_docs.gemspec
|
61
|
-
- fixtures/a/b/c.js
|
62
|
-
- fixtures/a/b/d.js
|
81
|
+
- fixtures/_design/a/b/c.js
|
82
|
+
- fixtures/_design/a/b/d.js
|
83
|
+
- fixtures/bar.json
|
84
|
+
- fixtures/foo.json
|
63
85
|
- lib/couch_design_docs.rb
|
64
|
-
- lib/couch_design_docs/
|
86
|
+
- lib/couch_design_docs/design_directory.rb
|
87
|
+
- lib/couch_design_docs/document_directory.rb
|
65
88
|
- lib/couch_design_docs/store.rb
|
66
89
|
- spec/couch_design_docs_spec.rb
|
67
90
|
- spec/spec_helper.rb
|
68
91
|
- test/test_couch_design_docs.rb
|
69
92
|
has_rdoc: true
|
70
93
|
homepage: http://github.com/eee-c/couch_design_docs
|
94
|
+
licenses:
|
71
95
|
post_install_message:
|
72
96
|
rdoc_options:
|
73
97
|
- --main
|
@@ -89,9 +113,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
113
|
requirements: []
|
90
114
|
|
91
115
|
rubyforge_project: couch_design_docs
|
92
|
-
rubygems_version: 1.
|
116
|
+
rubygems_version: 1.3.5
|
93
117
|
signing_key:
|
94
118
|
specification_version: 2
|
95
|
-
summary: Manage CouchDB views
|
119
|
+
summary: Manage CouchDB views and documents
|
96
120
|
test_files:
|
97
121
|
- test/test_couch_design_docs.rb
|