eee-c-couch_design_docs 1.0.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 ADDED
@@ -0,0 +1,4 @@
1
+ == 1.0.0 / 2009-07-08
2
+
3
+ * 1 major enhancement
4
+ * Birthday!
data/README.txt ADDED
@@ -0,0 +1,50 @@
1
+ couch_design_docs
2
+ by Chris Strom
3
+ http://github.com/eee-c/couch_design_docs
4
+
5
+ == DESCRIPTION:
6
+
7
+ Manage CouchDB views.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * Not acutally working just yet :)
12
+
13
+ == SYNOPSIS:
14
+
15
+ CouchDesignDocs.load(COUCHDB_VIEW_DIRECTORY)
16
+
17
+ == REQUIREMENTS:
18
+
19
+ * CouchDB
20
+ * JSON
21
+ * RestClient
22
+
23
+ == INSTALL:
24
+
25
+ * sudo gem install couch_view
26
+
27
+ == LICENSE:
28
+
29
+ (The MIT License)
30
+
31
+ Copyright (c) 2009
32
+
33
+ Permission is hereby granted, free of charge, to any person obtaining
34
+ a copy of this software and associated documentation files (the
35
+ 'Software'), to deal in the Software without restriction, including
36
+ without limitation the rights to use, copy, modify, merge, publish,
37
+ distribute, sublicense, and/or sell copies of the Software, and to
38
+ permit persons to whom the Software is furnished to do so, subject to
39
+ the following conditions:
40
+
41
+ The above copyright notice and this permission notice shall be
42
+ included in all copies or substantial portions of the Software.
43
+
44
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
45
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
46
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
47
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
48
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
49
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
50
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ # Look in the tasks/setup.rb file for the various options that can be
2
+ # configured in this Rakefile. The .rake files in the tasks directory
3
+ # are where the options are used.
4
+
5
+ begin
6
+ require 'bones'
7
+ Bones.setup
8
+ rescue LoadError
9
+ begin
10
+ load 'tasks/setup.rb'
11
+ rescue LoadError
12
+ raise RuntimeError, '### please install the "bones" gem ###'
13
+ end
14
+ end
15
+
16
+ ensure_in_path 'lib'
17
+ require 'couch_design_docs'
18
+
19
+ task :default => 'spec:run'
20
+
21
+ PROJ.name = 'couch_design_docs'
22
+ PROJ.authors = 'Chris Strom'
23
+ PROJ.email = 'chris@eeecooks.com'
24
+ PROJ.url = 'http://github.com/eee-c/couch_design_docs'
25
+ PROJ.version = CouchDesignDocs::VERSION
26
+ PROJ.rubyforge.name = 'couch_design_docs'
27
+
28
+ PROJ.spec.opts << '--color'
29
+
30
+ PROJ.gem.dependencies = %w{json jchris-couchrest}
31
+
32
+ # EOF
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(
4
+ File.join(File.dirname(__FILE__), %w[.. lib couch_design_docs]))
5
+
6
+ # Put your code here
7
+
8
+ # EOF
data/fixtures/a/b/c.js ADDED
@@ -0,0 +1 @@
1
+ function(doc) { return true; }
data/fixtures/a/b/d.js ADDED
@@ -0,0 +1 @@
1
+ function(doc) { return true; }
@@ -0,0 +1,49 @@
1
+
2
+ module CouchDesignDocs
3
+
4
+ # :stopdoc:
5
+ VERSION = '1.0.0'
6
+ LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
7
+ PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
8
+ # :startdoc:
9
+
10
+ # Returns the version string for the library.
11
+ #
12
+ def self.version
13
+ VERSION
14
+ end
15
+
16
+ # Returns the library path for the module. If any arguments are given,
17
+ # they will be joined to the end of the libray path using
18
+ # <tt>File.join</tt>.
19
+ #
20
+ def self.libpath( *args )
21
+ args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
22
+ end
23
+
24
+ # Returns the lpath for the module. If any arguments are given,
25
+ # they will be joined to the end of the path using
26
+ # <tt>File.join</tt>.
27
+ #
28
+ def self.path( *args )
29
+ args.empty? ? PATH : ::File.join(PATH, args.flatten)
30
+ end
31
+
32
+ # Utility method used to require all files ending in .rb that lie in the
33
+ # directory below this file that has the same name as the filename passed
34
+ # in. Optionally, a specific _directory_ name can be passed in such that
35
+ # the _filename_ does not have to be equivalent to the directory.
36
+ #
37
+ def self.require_all_libs_relative_to( fname, dir = nil )
38
+ dir ||= ::File.basename(fname, '.*')
39
+ search_me = ::File.expand_path(
40
+ ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
41
+
42
+ Dir.glob(search_me).sort.each {|rb| require rb}
43
+ end
44
+
45
+ end # module CouchDesignDocs
46
+
47
+ CouchDesignDocs.require_all_libs_relative_to(__FILE__)
48
+
49
+ # EOF
@@ -0,0 +1,48 @@
1
+ require 'pp'
2
+
3
+ class Hash
4
+ def deep_merge(other)
5
+ self.merge(other) do |key, oldval, newval|
6
+ oldval.deep_merge(newval)
7
+ end
8
+ end
9
+ end
10
+
11
+ module CouchDesignDocs
12
+ class Directory
13
+
14
+ attr_accessor :couch_view_dir
15
+
16
+ def self.a_to_hash(a)
17
+ key = a.first
18
+ if (a.length > 2)
19
+ { key => a_to_hash(a[1,a.length]) }
20
+ else
21
+ { key => a.last }
22
+ end
23
+ end
24
+
25
+ def initialize(path)
26
+ Dir.new(path) # Just checkin'
27
+ @couch_view_dir = path
28
+ end
29
+
30
+ def to_hash
31
+ Dir["#{couch_view_dir}/**/*.js"].inject({}) do |memo, filename|
32
+ Directory.
33
+ a_to_hash(expand_file(filename)).
34
+ deep_merge(memo)
35
+ end
36
+ end
37
+
38
+ def expand_file(filename)
39
+ File.dirname(filename).
40
+ gsub(/#{couch_view_dir}\/?/, '').
41
+ split(/\//) +
42
+ [
43
+ File.basename(filename, '.js'),
44
+ File.new(filename).read
45
+ ]
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,20 @@
1
+ require 'rest_client'
2
+ require 'json'
3
+
4
+ module CouchDesignDocs
5
+ class Store
6
+ attr_accessor :url
7
+
8
+ def initialize(url)
9
+ @url = url
10
+ end
11
+
12
+ def load(h)
13
+ h.each_pair do |document_name, doc|
14
+ RestClient.put "#{url}/_design/#{document_name}",
15
+ doc.to_json,
16
+ :content_type => 'application/json'
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,85 @@
1
+ require File.join(File.dirname(__FILE__), %w[spec_helper])
2
+
3
+ describe Store do
4
+ it "should require a CouchDB URL Root for instantiation" do
5
+ lambda { Store.new }.
6
+ should raise_error
7
+
8
+ lambda { Store.new("uri") }.
9
+ should_not raise_error
10
+ end
11
+
12
+ context "a valid store" do
13
+ before(:each) do
14
+ @it = Store.new("uri")
15
+
16
+ @hash = {
17
+ 'a' => {
18
+ 'b' => {
19
+ 'c' => 'function(doc) { return true; }'
20
+ }
21
+ }
22
+ }
23
+ end
24
+
25
+ it "should be able to load a hash into design docs" do
26
+ RestClient.
27
+ should_receive(:put).
28
+ with("uri/_design/a",
29
+ '{"b":{"c":"function(doc) { return true; }"}}',
30
+ :content_type => 'application/json')
31
+ @it.load(@hash)
32
+ end
33
+ end
34
+ end
35
+
36
+ describe Directory do
37
+ it "should require a root directory for instantiation" do
38
+ lambda { Directory.new }.
39
+ should raise_error
40
+
41
+ lambda { Directory.new("foo") }.
42
+ should raise_error
43
+
44
+ lambda { Directory.new("fixtures")}.
45
+ should_not raise_error
46
+ end
47
+
48
+ it "should convert arrays into deep hashes" do
49
+ Directory.
50
+ a_to_hash(%w{a b c d}).
51
+ should == {
52
+ 'a' => {
53
+ 'b' => {
54
+ 'c' => 'd'
55
+ }
56
+ }
57
+ }
58
+ end
59
+
60
+ context "a valid directory" do
61
+ before(:each) do
62
+ @it = Directory.new("fixtures")
63
+ end
64
+
65
+ it "should list dirs, basename and contents of a file" do
66
+ @it.expand_file("fixtures/a/b/c.js").
67
+ should == ['a', 'b', 'c', 'function(doc) { return true; }']
68
+ end
69
+
70
+ it "should assemble all documents into a single docs structure" do
71
+ @it.to_hash.
72
+ should == {
73
+ 'a' => {
74
+ 'b' => {
75
+ 'c' => 'function(doc) { return true; }',
76
+ 'd' => 'function(doc) { return true; }'
77
+ }
78
+ }
79
+
80
+ }
81
+ end
82
+ end
83
+ end
84
+
85
+ # EOF
@@ -0,0 +1,18 @@
1
+
2
+ require File.expand_path(
3
+ File.join(File.dirname(__FILE__), %w[.. lib couch_design_docs]))
4
+
5
+ include CouchDesignDocs
6
+
7
+ Spec::Runner.configure do |config|
8
+ # == Mock Framework
9
+ #
10
+ # RSpec uses it's own mocking framework by default. If you prefer to
11
+ # use mocha, flexmock or RR, uncomment the appropriate line:
12
+ #
13
+ # config.mock_with :mocha
14
+ # config.mock_with :flexmock
15
+ # config.mock_with :rr
16
+ end
17
+
18
+ # EOF
File without changes
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eee-c-couch_design_docs
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Strom
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-11 00:00:00 -07:00
13
+ default_executable: couch_design_docs
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: json
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: jchris-couchrest
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: bones
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 2.5.1
44
+ version:
45
+ description: Manage CouchDB views.
46
+ email: chris@eeecooks.com
47
+ executables:
48
+ - couch_design_docs
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - History.txt
53
+ - README.txt
54
+ - bin/couch_design_docs
55
+ files:
56
+ - History.txt
57
+ - README.txt
58
+ - Rakefile
59
+ - bin/couch_design_docs
60
+ - fixtures/a/b/c.js
61
+ - fixtures/a/b/d.js
62
+ - lib/couch_design_docs.rb
63
+ - lib/couch_design_docs/directory.rb
64
+ - lib/couch_design_docs/store.rb
65
+ - spec/couch_design_docs_spec.rb
66
+ - spec/spec_helper.rb
67
+ - test/test_couch_design_docs.rb
68
+ has_rdoc: true
69
+ homepage: http://github.com/eee-c/couch_design_docs
70
+ post_install_message:
71
+ rdoc_options:
72
+ - --main
73
+ - README.txt
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: "0"
81
+ version:
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: "0"
87
+ version:
88
+ requirements: []
89
+
90
+ rubyforge_project: couch_design_docs
91
+ rubygems_version: 1.2.0
92
+ signing_key:
93
+ specification_version: 2
94
+ summary: Manage CouchDB views
95
+ test_files:
96
+ - test/test_couch_design_docs.rb