eee-c-couch_design_docs 1.0.1 → 1.0.2
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 +5 -0
- data/README.txt +12 -3
- data/couch_design_docs.gemspec +2 -2
- data/lib/couch_design_docs.rb +12 -1
- data/lib/couch_design_docs/store.rb +10 -2
- data/spec/couch_design_docs_spec.rb +18 -0
- metadata +2 -2
data/History.txt
CHANGED
data/README.txt
CHANGED
@@ -8,11 +8,20 @@ Manage CouchDB views.
|
|
8
8
|
|
9
9
|
== FEATURES/PROBLEMS:
|
10
10
|
|
11
|
-
*
|
11
|
+
* Allows you to store your CouchDB design documents on the file system
|
12
|
+
with <tt>.js</tt> extensions.
|
12
13
|
|
13
14
|
== SYNOPSIS:
|
14
15
|
|
15
|
-
|
16
|
+
DB_URL = "http://localhost:5984/db"
|
17
|
+
DIRECTORY = "/repos/db/coudb/_design"
|
18
|
+
|
19
|
+
# /repos/db/coudb/_design/lucene/transform.js
|
20
|
+
|
21
|
+
CouchDesignDocs.upload_dir(DB_URL, DIRECTORY)
|
22
|
+
|
23
|
+
# => lucene design document with a "transform" function containing
|
24
|
+
# the contents of transform.js
|
16
25
|
|
17
26
|
== REQUIREMENTS:
|
18
27
|
|
@@ -22,7 +31,7 @@ Manage CouchDB views.
|
|
22
31
|
|
23
32
|
== INSTALL:
|
24
33
|
|
25
|
-
* sudo gem install
|
34
|
+
* sudo gem install couch_design_docs
|
26
35
|
|
27
36
|
== LICENSE:
|
28
37
|
|
data/couch_design_docs.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
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.0.2"
|
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-13}
|
10
10
|
s.default_executable = %q{couch_design_docs}
|
11
11
|
s.description = %q{Manage CouchDB views.}
|
12
12
|
s.email = %q{chris@eeecooks.com}
|
data/lib/couch_design_docs.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
+
require 'pp'
|
1
2
|
|
2
3
|
module CouchDesignDocs
|
3
4
|
|
4
5
|
# :stopdoc:
|
5
|
-
VERSION = '1.0.
|
6
|
+
VERSION = '1.0.2'
|
6
7
|
LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
|
7
8
|
PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
|
8
9
|
# :startdoc:
|
@@ -13,6 +14,16 @@ module CouchDesignDocs
|
|
13
14
|
VERSION
|
14
15
|
end
|
15
16
|
|
17
|
+
# For a CouchDB database described by <tt>db_uri</tt> and a
|
18
|
+
# directory, <tt>dir</tt> containing design documents, creates
|
19
|
+
# design documents in the CouchDB database
|
20
|
+
#
|
21
|
+
def self.upload_dir(db_uri, dir)
|
22
|
+
store = Store.new(db_uri)
|
23
|
+
dir = Directory.new(dir)
|
24
|
+
store.load(dir.to_hash)
|
25
|
+
end
|
26
|
+
|
16
27
|
# Returns the library path for the module. If any arguments are given,
|
17
28
|
# they will be joined to the end of the libray path using
|
18
29
|
# <tt>File.join</tt>.
|
@@ -5,18 +5,26 @@ module CouchDesignDocs
|
|
5
5
|
class Store
|
6
6
|
attr_accessor :url
|
7
7
|
|
8
|
+
# Initialize a CouchDB store object. Requires a URL for the
|
9
|
+
# target CouchDB database.
|
10
|
+
#
|
8
11
|
def initialize(url)
|
9
12
|
@url = url
|
10
13
|
end
|
11
14
|
|
15
|
+
# Loads all supplied designed documents in the current store.
|
16
|
+
# Given a hash <tt>h</tt>, the keys being the CouchDB document
|
17
|
+
# name and values of design documents
|
18
|
+
#
|
12
19
|
def load(h)
|
13
20
|
h.each_pair do |document_name, doc|
|
14
21
|
Store.put!("#{url}/_design/#{document_name}", doc)
|
15
22
|
end
|
16
23
|
end
|
17
24
|
|
18
|
-
# Create or replace the document located at
|
19
|
-
# Hash document
|
25
|
+
# Create or replace the document located at <tt>path</tt> with the
|
26
|
+
# Hash document <tt>doc</tt>
|
27
|
+
#
|
20
28
|
def self.put!(path, doc)
|
21
29
|
self.put(path, doc)
|
22
30
|
rescue RestClient::RequestFailed
|
@@ -1,5 +1,23 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), %w[spec_helper])
|
2
2
|
|
3
|
+
describe CouchDesignDocs do
|
4
|
+
it "should be able to load directory/JS files into CouchDB as design docs" do
|
5
|
+
store = mock("Store")
|
6
|
+
Store.stub!(:new).and_return(store)
|
7
|
+
|
8
|
+
dir = mock("Directory")
|
9
|
+
dir.stub!(:to_hash).and_return({ "foo" => "bar" })
|
10
|
+
Directory.stub!(:new).and_return(dir)
|
11
|
+
|
12
|
+
store.
|
13
|
+
should_receive(:load).
|
14
|
+
with({ "foo" => "bar" })
|
15
|
+
|
16
|
+
CouchDesignDocs.upload_dir("uri", "fixtures")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
3
21
|
describe Store do
|
4
22
|
it "should require a CouchDB URL Root for instantiation" do
|
5
23
|
lambda { Store.new }.
|
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.0.2
|
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-13 00:00:00 -07:00
|
13
13
|
default_executable: couch_design_docs
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|