couch_docs 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ == 1.2.0 / 2010-03-29
2
+
3
+ * Directory watcher only applies individual changes, not entire
4
+ directory when individual changes are made.
5
+
1
6
  == 1.1.1 / 2010-03-15
2
7
 
3
8
  * Require RestClient 1.1.
Binary file
data/couch_docs.gemspec CHANGED
@@ -2,17 +2,17 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{couch_docs}
5
- s.version = "1.1.1"
5
+ s.version = "1.2.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{2010-03-15}
9
+ s.date = %q{2010-03-30}
10
10
  s.default_executable = %q{couch-docs}
11
11
  s.description = %q{Manage CouchDB views and documents.}
12
12
  s.email = %q{chris@eeecooks.com}
13
13
  s.executables = ["couch-docs"]
14
14
  s.extra_rdoc_files = ["History.txt", "README.rdoc", "bin/couch-docs"]
15
- s.files = ["History.txt", "README.rdoc", "Rakefile", "bin/couch-docs", "couch_docs-1.1.0.gem", "couch_docs.gemspec", "fixtures/_design/__lib/foo.js", "fixtures/_design/a/b/c.js", "fixtures/_design/a/b/d.js", "fixtures/_design/x/z.js", "fixtures/bar.json", "fixtures/foo.json", "lib/couch_docs.rb", "lib/couch_docs/command_line.rb", "lib/couch_docs/design_directory.rb", "lib/couch_docs/document_directory.rb", "lib/couch_docs/store.rb", "spec/couch_docs_spec.rb", "spec/spec_helper.rb", "test/test_couch_docs.rb"]
15
+ s.files = ["History.txt", "README.rdoc", "Rakefile", "bin/couch-docs", "couch_docs-1.1.0.gem", "couch_docs-1.1.1.gem", "couch_docs.gemspec", "fixtures/_design/__lib/foo.js", "fixtures/_design/a/b/c.js", "fixtures/_design/a/b/d.js", "fixtures/_design/x/z.js", "fixtures/bar.json", "fixtures/foo.json", "lib/couch_docs.rb", "lib/couch_docs/command_line.rb", "lib/couch_docs/design_directory.rb", "lib/couch_docs/document_directory.rb", "lib/couch_docs/store.rb", "spec/couch_docs_spec.rb", "spec/spec_helper.rb", "test/test_couch_docs.rb"]
16
16
  s.homepage = %q{http://github.com/eee-c/couch_docs}
17
17
  s.rdoc_options = ["--main", "README.rdoc"]
18
18
  s.require_paths = ["lib"]
@@ -34,15 +34,14 @@ module CouchDocs
34
34
 
35
35
  dw.add_observer do |*args|
36
36
  puts "Updating documents on CouchDB Server..."
37
- CouchDocs.put_dir(@options[:couchdb_url],
38
- @options[:target_dir])
37
+ directory_watcher_update(args)
39
38
  end
40
39
 
41
40
  if @options[:watch]
42
41
  dw.start
43
42
 
44
43
  begin
45
- sleep 30 while true
44
+ sleep 30 while active?
46
45
  rescue Interrupt
47
46
  dw.stop
48
47
  puts
@@ -131,5 +130,36 @@ module CouchDocs
131
130
  raise e
132
131
  end
133
132
  end
133
+
134
+ def directory_watcher_update(args)
135
+ if initial_add? args
136
+ CouchDocs.put_dir(@options[:couchdb_url],
137
+ @options[:target_dir])
138
+ else
139
+ if design_doc_update? args
140
+ CouchDocs.put_design_dir(@options[:couchdb_url],
141
+ "#{@options[:target_dir]}/_design")
142
+ end
143
+ documents(args).each do |update|
144
+ CouchDocs.put_file(@options[:couchdb_url],
145
+ update.path)
146
+ end
147
+ end
148
+ end
149
+
150
+ def initial_add?(args)
151
+ args.all? { |f| f.type == :added }
152
+ end
153
+
154
+ def design_doc_update?(args)
155
+ args.any? { |f| f.path =~ /_design/ }
156
+ end
157
+
158
+ def documents(args)
159
+ args.reject { |f| f.path =~ /_design/ }
160
+ end
161
+
162
+ private
163
+ def active?; true end
134
164
  end
135
165
  end
data/lib/couch_docs.rb CHANGED
@@ -3,7 +3,7 @@ require 'ostruct'
3
3
  module CouchDocs
4
4
 
5
5
  # :stopdoc:
6
- VERSION = '1.1.1'
6
+ VERSION = '1.2.0'
7
7
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
8
8
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
9
9
  # :startdoc:
@@ -41,13 +41,22 @@ module CouchDocs
41
41
  # located at <tt>db_uri</tt>
42
42
  #
43
43
  def self.put_document_dir(db_uri, dir)
44
- store = Store.new(db_uri)
45
44
  dir = DocumentDirectory.new(dir)
46
45
  dir.each_document do |name, contents|
47
46
  Store.put!("#{db_uri}/#{name}", contents)
48
47
  end
49
48
  end
50
49
 
50
+
51
+ # Upload a document located at <tt>file_path</tt> to the CouchDB database
52
+ # located at <tt>db_uri</tt>
53
+ #
54
+ def self.put_file(db_uri, file_path)
55
+ contents = JSON.parse(File.read(file_path))
56
+ name = File.basename(file_path, ".json")
57
+ Store.put!("#{db_uri}/#{name}", contents)
58
+ end
59
+
51
60
  # Dump all documents located at <tt>db_uri</tt> into the directory
52
61
  # <tt>dir</tt>
53
62
  #
@@ -37,9 +37,6 @@ describe CouchDocs do
37
37
  end
38
38
 
39
39
  it "should be able to load documents into CouchDB" do
40
- store = mock("Store")
41
- Store.stub!(:new).and_return(store)
42
-
43
40
  dir = mock("Document Directory")
44
41
  dir.
45
42
  stub!(:each_document).
@@ -54,6 +51,16 @@ describe CouchDocs do
54
51
  CouchDocs.put_document_dir("uri", "fixtures")
55
52
  end
56
53
 
54
+ it "should be able to upload a single document into CouchDB" do
55
+ Store.
56
+ should_receive(:put!).
57
+ with('uri/foo', {"foo" => "1"})
58
+
59
+ File.stub!(:read).and_return('{"foo": "1"}')
60
+
61
+ CouchDocs.put_file("uri", "/foo")
62
+ end
63
+
57
64
  context "dumping CouchDB documents to a directory" do
58
65
  before(:each) do
59
66
  @store = mock("Store")
@@ -464,6 +471,78 @@ describe CommandLine do
464
471
 
465
472
  @it.run
466
473
  end
474
+
475
+ it "should be an initial add if everything is an add" do
476
+ @it = CommandLine.new(['push', 'uri'])
477
+ args = [mock(:type => :added),
478
+ mock(:type => :added)]
479
+ @it.should be_initial_add(args)
480
+ end
481
+
482
+ it "should not be an initial add if something is not an add" do
483
+ @it = CommandLine.new(['push', 'uri'])
484
+ args = [mock(:type => :foo),
485
+ mock(:type => :added)]
486
+ @it.should_not be_initial_add(args)
487
+ end
488
+
489
+ it "should be a design docs update if something changes in _design" do
490
+ @it = CommandLine.new(['push', 'uri'])
491
+ args = [mock(:path => "foo"),
492
+ mock(:path => "_design")]
493
+ @it.should be_design_doc_update(args)
494
+ end
495
+
496
+ it "should know document updates" do
497
+ @it = CommandLine.new(['push', 'uri'])
498
+ doc_update = mock(:path => "foo")
499
+ args = [doc_update,
500
+ mock(:path => "_design")]
501
+
502
+ @it.
503
+ documents(args).
504
+ should == [doc_update]
505
+ end
506
+
507
+
508
+ context "updates on the filesystem" do
509
+ before(:each) do
510
+ @args = mock("args")
511
+ @it = CommandLine.new(%w(push uri dir))
512
+ end
513
+ it "should only update design docs if only local design docs have changed" do
514
+ CouchDocs.
515
+ should_receive(:put_dir)
516
+
517
+ @it.stub!(:initial_add?).and_return(true)
518
+ @it.directory_watcher_update(@args)
519
+ end
520
+ context "not an inital add" do
521
+ before(:each) do
522
+ @it.stub!(:initial_add?).and_return(false)
523
+ @it.stub!(:design_doc_update?).and_return(false)
524
+ @it.stub!(:documents).and_return([])
525
+ CouchDocs.stub!(:put_design_dir)
526
+ end
527
+ it "should update design docs if there are design document updates" do
528
+ CouchDocs.
529
+ should_receive(:put_design_dir)
530
+
531
+ @it.stub!(:design_doc_update?).and_return(true)
532
+ @it.directory_watcher_update(@args)
533
+ end
534
+ it "should update documents (if any)" do
535
+ file_mock = mock("File", :path => "/foo")
536
+ @it.stub!(:documents).and_return([file_mock])
537
+
538
+ CouchDocs.
539
+ should_receive(:put_file).
540
+ with("uri", "/foo")
541
+
542
+ @it.directory_watcher_update(@args)
543
+ end
544
+ end
545
+ end
467
546
  end
468
547
 
469
548
  context "pushing" do
@@ -490,6 +569,7 @@ describe CommandLine do
490
569
  @dw.should_receive(:start)
491
570
 
492
571
  @it = CommandLine.new(%w(push uri dir -w))
572
+ @it.stub!(:active?).and_return(false)
493
573
  @it.run
494
574
  end
495
575
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: couch_docs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.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: 2010-03-15 00:00:00 -04:00
12
+ date: 2010-03-30 00:00:00 -04:00
13
13
  default_executable: couch-docs
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -78,6 +78,7 @@ files:
78
78
  - Rakefile
79
79
  - bin/couch-docs
80
80
  - couch_docs-1.1.0.gem
81
+ - couch_docs-1.1.1.gem
81
82
  - couch_docs.gemspec
82
83
  - fixtures/_design/__lib/foo.js
83
84
  - fixtures/_design/a/b/c.js