couchrest 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ html/*
3
+ pkg
4
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+
2
+ source :rubygems
3
+ gemspec
4
+
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ couchrest (1.0.2)
5
+ json (~> 1.5.1)
6
+ mime-types (~> 1.15)
7
+ rest-client (~> 1.6.1)
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ json (1.5.1-java)
13
+ mime-types (1.16)
14
+ rest-client (1.6.1)
15
+ mime-types (>= 1.16)
16
+ rspec (1.3.1)
17
+
18
+ PLATFORMS
19
+ java
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ couchrest!
24
+ rspec (~> 1.3.0)
data/README.md CHANGED
@@ -18,17 +18,30 @@ CouchRest is designed to make a simple base for application and framework-specif
18
18
 
19
19
  CouchRest rests on top of a HTTP abstraction layer using by default Heroku’s excellent REST Client Ruby HTTP wrapper.
20
20
 
21
+ ## Modelling
22
+
23
+ For more complete modelling support based on Rails 3's ActiveModel, please checkout CouchRest's sister project: [CouchRest Model](https://github.com/couchrest/couchrest_model).
24
+
21
25
  ## Extended Document
22
26
 
23
27
  As of May 2010 support for the popular CouchRest::ExtendedDocument mixin has been moved to its own gem: [couchrest_extended_document](http://github.com/couchrest/couchrest_extended_document).
24
28
 
25
- Most people will probably want to use this library (or one of the alternatives) to make it slightly easier to access your documents.
29
+ If you're starting a new project however, we recommend you use the more actively maintained [CouchRest Model](https://github.com/couchrest/couchrest_model) project, supported by the same team of developers.
26
30
 
27
31
  ## Running the Specs
28
32
 
29
33
  The most complete documentation is the spec/ directory. To validate your
30
- CouchRest install, from the project root directory run `rake`, or `autotest`
31
- (requires RSpec and optionally ZenTest for autotest support).
34
+ CouchRest install, from the project root directory use bundler to install
35
+ the dependencies and then run the tests:
36
+
37
+ $ bundle install
38
+ $ bundle exec spec spec
39
+
40
+ To date, the couchrest specs have been show to run on:
41
+
42
+ * Ruby 1.8.7
43
+ * Ruby 1.9.2
44
+ * JRuby 1.5.6
32
45
 
33
46
  ## Docs
34
47
 
data/Rakefile CHANGED
@@ -1,3 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler::GemHelper.install_tasks
4
+
1
5
  require 'rake'
2
6
  require "rake/rdoctask"
3
7
 
@@ -14,29 +18,6 @@ EOS
14
18
  exit(0)
15
19
  end
16
20
 
17
- begin
18
- require 'jeweler'
19
- Jeweler::Tasks.new do |gemspec|
20
- gemspec.name = "couchrest"
21
- gemspec.summary = "Lean and RESTful interface to CouchDB."
22
- gemspec.description = "CouchRest provides a simple interface on top of CouchDB's RESTful HTTP API, as well as including some utility scripts for managing views and attachments."
23
- gemspec.email = "jchris@apache.org"
24
- gemspec.homepage = "http://github.com/couchrest/couchrest"
25
- gemspec.authors = ["J. Chris Anderson", "Matt Aimonetti", "Marcos Tapajos", "Will Leinweber", "Sam Lown"]
26
- gemspec.extra_rdoc_files = %w( README.md LICENSE THANKS.md )
27
- gemspec.files = %w( LICENSE README.md Rakefile THANKS.md history.txt couchrest.gemspec) + Dir["{examples,lib,spec,utils}/**/*"] - Dir["spec/tmp"]
28
- gemspec.has_rdoc = true
29
- gemspec.add_dependency("rest-client", ">= 1.5.1")
30
- gemspec.add_dependency("mime-types", ">= 1.15")
31
- gemspec.add_dependency("json", ">= 1.4.6")
32
- gemspec.version = CouchRest::VERSION
33
- gemspec.date = Time.now.strftime("%Y-%m-%d")
34
- gemspec.require_path = "lib"
35
- end
36
- rescue LoadError
37
- puts "Jeweler not available. Install it with: gem install jeweler"
38
- end
39
-
40
21
  desc "Run all specs"
41
22
  Spec::Rake::SpecTask.new('spec') do |t|
42
23
  t.spec_opts = ["--color"]
@@ -1,111 +1,34 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
1
  # -*- encoding: utf-8 -*-
5
2
 
6
3
  Gem::Specification.new do |s|
7
4
  s.name = %q{couchrest}
8
- s.version = "1.0.1"
5
+ s.version = "1.0.2"
9
6
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
7
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
8
  s.authors = ["J. Chris Anderson", "Matt Aimonetti", "Marcos Tapajos", "Will Leinweber", "Sam Lown"]
12
- s.date = %q{2010-08-18}
9
+ s.date = %q{2011-03-13}
13
10
  s.description = %q{CouchRest provides a simple interface on top of CouchDB's RESTful HTTP API, as well as including some utility scripts for managing views and attachments.}
14
11
  s.email = %q{jchris@apache.org}
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ s.require_paths = ["lib"]
17
+
15
18
  s.extra_rdoc_files = [
16
19
  "LICENSE",
17
- "README.md",
18
- "THANKS.md"
19
- ]
20
- s.files = [
21
- "LICENSE",
22
- "README.md",
23
- "Rakefile",
24
- "THANKS.md",
25
- "couchrest.gemspec",
26
- "examples/word_count/markov",
27
- "examples/word_count/views/books/chunked-map.js",
28
- "examples/word_count/views/books/united-map.js",
29
- "examples/word_count/views/markov/chain-map.js",
30
- "examples/word_count/views/markov/chain-reduce.js",
31
- "examples/word_count/views/word_count/count-map.js",
32
- "examples/word_count/views/word_count/count-reduce.js",
33
- "examples/word_count/word_count.rb",
34
- "examples/word_count/word_count_query.rb",
35
- "examples/word_count/word_count_views.rb",
36
- "history.txt",
37
- "lib/couchrest.rb",
38
- "lib/couchrest/commands/generate.rb",
39
- "lib/couchrest/commands/push.rb",
40
- "lib/couchrest/database.rb",
41
- "lib/couchrest/design.rb",
42
- "lib/couchrest/document.rb",
43
- "lib/couchrest/helper/attachments.rb",
44
- "lib/couchrest/helper/pager.rb",
45
- "lib/couchrest/helper/streamer.rb",
46
- "lib/couchrest/helper/upgrade.rb",
47
- "lib/couchrest/middlewares/logger.rb",
48
- "lib/couchrest/monkeypatches.rb",
49
- "lib/couchrest/response.rb",
50
- "lib/couchrest/rest_api.rb",
51
- "lib/couchrest/server.rb",
52
- "lib/couchrest/support/inheritable_attributes.rb",
53
- "spec/couchrest/couchrest_spec.rb",
54
- "spec/couchrest/database_spec.rb",
55
- "spec/couchrest/design_spec.rb",
56
- "spec/couchrest/document_spec.rb",
57
- "spec/couchrest/helpers/pager_spec.rb",
58
- "spec/couchrest/helpers/streamer_spec.rb",
59
- "spec/couchrest/server_spec.rb",
60
- "spec/fixtures/attachments/README",
61
- "spec/fixtures/attachments/couchdb.png",
62
- "spec/fixtures/attachments/test.html",
63
- "spec/fixtures/views/lib.js",
64
- "spec/fixtures/views/test_view/lib.js",
65
- "spec/fixtures/views/test_view/only-map.js",
66
- "spec/fixtures/views/test_view/test-map.js",
67
- "spec/fixtures/views/test_view/test-reduce.js",
68
- "spec/spec.opts",
69
- "spec/spec_helper.rb",
70
- "utils/remap.rb",
71
- "utils/subset.rb"
20
+ "README.md",
21
+ "THANKS.md"
72
22
  ]
73
23
  s.homepage = %q{http://github.com/couchrest/couchrest}
74
24
  s.rdoc_options = ["--charset=UTF-8"]
75
25
  s.require_paths = ["lib"]
76
26
  s.rubygems_version = %q{1.3.7}
77
27
  s.summary = %q{Lean and RESTful interface to CouchDB.}
78
- s.test_files = [
79
- "spec/spec_helper.rb",
80
- "spec/couchrest/couchrest_spec.rb",
81
- "spec/couchrest/server_spec.rb",
82
- "spec/couchrest/document_spec.rb",
83
- "spec/couchrest/design_spec.rb",
84
- "spec/couchrest/database_spec.rb",
85
- "spec/couchrest/helpers/pager_spec.rb",
86
- "spec/couchrest/helpers/streamer_spec.rb",
87
- "examples/word_count/word_count_views.rb",
88
- "examples/word_count/word_count_query.rb",
89
- "examples/word_count/word_count.rb"
90
- ]
91
28
 
92
- if s.respond_to? :specification_version then
93
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
94
- s.specification_version = 3
29
+ s.add_dependency(%q<rest-client>, ["~> 1.6.1"])
30
+ s.add_dependency(%q<mime-types>, ["~> 1.15"])
31
+ s.add_dependency(%q<json>, ["~> 1.5.1"])
32
+ s.add_development_dependency(%q<rspec>, "~> 1.3.0")
95
33
 
96
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
97
- s.add_runtime_dependency(%q<rest-client>, [">= 1.5.1"])
98
- s.add_runtime_dependency(%q<mime-types>, [">= 1.15"])
99
- s.add_runtime_dependency(%q<json>, [">= 1.4.6"])
100
- else
101
- s.add_dependency(%q<rest-client>, [">= 1.5.1"])
102
- s.add_dependency(%q<mime-types>, [">= 1.15"])
103
- s.add_dependency(%q<json>, [">= 1.4.6"])
104
- end
105
- else
106
- s.add_dependency(%q<rest-client>, [">= 1.5.1"])
107
- s.add_dependency(%q<mime-types>, [">= 1.15"])
108
- s.add_dependency(%q<json>, [">= 1.4.6"])
109
- end
110
34
  end
111
-
@@ -1,8 +1,10 @@
1
- == Next Version
2
-
3
- * Major enhancements
1
+ == 1.0.2
4
2
 
5
3
  * Minor enhancements
4
+ * Bundler
5
+ * Dependency versions upgrade
6
+ * Removed reduce option from view's defaults. Now detected according to presence of reduce function.
7
+ * Design#has_view? and Design#can_reduce_view? now available publically
6
8
 
7
9
  == 1.0.1
8
10
 
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__),'lib', 'couchrest.rb')
@@ -9,13 +9,10 @@ module CouchRest
9
9
  if opts[:map]
10
10
  view = {}
11
11
  view['map'] = opts.delete(:map)
12
- if opts[:reduce]
13
- view['reduce'] = opts.delete(:reduce)
14
- opts[:reduce] = false
15
- end
12
+ view['reduce'] = opts.delete(:reduce) if opts[:reduce]
16
13
  self['views'][method_name] = view
17
14
  else
18
- doc_keys = keys.collect{|k|"doc['#{k}']"} # this is where :require => 'doc.x == true' would show up
15
+ doc_keys = keys.collect{|k| "doc['#{k}']"}
19
16
  key_emit = doc_keys.length == 1 ? "#{doc_keys.first}" : "[#{doc_keys.join(', ')}]"
20
17
  guards = opts.delete(:guards) || []
21
18
  guards += doc_keys.map{|k| "(#{k} != null)"}
@@ -41,11 +38,15 @@ JAVASCRIPT
41
38
  end
42
39
 
43
40
  # Dispatches to any named view in a specific database
44
- def view_on db, view_name, query={}, &block
41
+ def view_on db, view_name, query = {}, &block
45
42
  view_name = view_name.to_s
46
43
  view_slug = "#{name}/#{view_name}"
47
- defaults = (self['views'][view_name] && self['views'][view_name]["couchrest-defaults"]) || {}
48
- db.view(view_slug, defaults.merge(query), &block)
44
+ # Set the default query options
45
+ query = view_defaults(view_name).merge(query)
46
+ # Ensure reduce is set if dealing with a reduceable view
47
+ # This is a requirement of CouchDB.
48
+ query['reduce'] ||= false if can_reduce_view?(view_name)
49
+ db.view(view_slug, query, &block)
49
50
  end
50
51
 
51
52
  def name
@@ -61,19 +62,27 @@ JAVASCRIPT
61
62
  super
62
63
  end
63
64
 
64
- private
65
+ # Return the hash of default values to include in all queries sent
66
+ # to a view from couchrest.
67
+ def view_defaults(name)
68
+ (self['views'][name.to_s] && self['views'][name.to_s]["couchrest-defaults"]) || {}
69
+ end
70
+
71
+ # Returns true or false if the view is available.
72
+ def has_view?(name)
73
+ !self['views'][name.to_s].nil?
74
+ end
65
75
 
66
- # returns stored defaults if the there is a view named this in the design doc
67
- def has_view?(view)
68
- view = view.to_s
69
- self['views'][view] &&
70
- (self['views'][view]["couchrest-defaults"] || {})
76
+ # Check if the view has a reduce method defined.
77
+ def can_reduce_view?(name)
78
+ has_view?(name) && !self['views'][name.to_s]['reduce'].to_s.empty?
71
79
  end
72
80
 
81
+ private
82
+
73
83
  def fetch_view view_name, opts, &block
74
84
  database.view(view_name, opts, &block)
75
85
  end
76
86
 
77
87
  end
78
-
79
88
  end
@@ -0,0 +1 @@
1
+ tmp
@@ -154,5 +154,29 @@ describe CouchRest::Design do
154
154
  end
155
155
  end
156
156
 
157
+ describe "a view with a reduce function" do
158
+ before(:all) do
159
+ @db = reset_test_db!
160
+ @des = CouchRest::Design.new
161
+ @des.name = "test"
162
+ @des.view_by :code, :map => "function(d){ if(d['code']) { emit(d['code'], 1); } }", :reduce => "function(k,v,r){ return sum(v); }"
163
+ @des.database = @db
164
+ @des.save
165
+ @db.bulk_save([{"code" => "a", "age" => 2},
166
+ {"code" => 'b', "age" => 4},{"code" => 'c', "age" => 9}])
167
+ end
168
+ it "should not set a default parameter" do
169
+ @des['views']['by_code']['couchrest-defaults'].should be_nil
170
+ end
171
+ it "should include reduce parameter in query" do
172
+ res = @des.view :by_code
173
+ res["rows"][0]["key"].should == 'a'
174
+ end
175
+ it "should allow reduce to be performed" do
176
+ res = @des.view :by_code, :reduce => true
177
+ res["rows"][0]["value"].should eql(3)
178
+ end
179
+ end
180
+
157
181
 
158
182
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 1
9
- version: 1.0.1
8
+ - 2
9
+ version: 1.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - J. Chris Anderson
@@ -18,7 +18,7 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2010-08-18 00:00:00 +02:00
21
+ date: 2011-03-13 00:00:00 +01:00
22
22
  default_executable:
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
@@ -27,13 +27,13 @@ dependencies:
27
27
  requirement: &id001 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
- - - ">="
30
+ - - ~>
31
31
  - !ruby/object:Gem::Version
32
32
  segments:
33
33
  - 1
34
- - 5
34
+ - 6
35
35
  - 1
36
- version: 1.5.1
36
+ version: 1.6.1
37
37
  type: :runtime
38
38
  version_requirements: *id001
39
39
  - !ruby/object:Gem::Dependency
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirement: &id002 !ruby/object:Gem::Requirement
43
43
  none: false
44
44
  requirements:
45
- - - ">="
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  segments:
48
48
  - 1
@@ -56,15 +56,30 @@ dependencies:
56
56
  requirement: &id003 !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
- - - ">="
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  segments:
62
62
  - 1
63
- - 4
64
- - 6
65
- version: 1.4.6
63
+ - 5
64
+ - 1
65
+ version: 1.5.1
66
66
  type: :runtime
67
67
  version_requirements: *id003
68
+ - !ruby/object:Gem::Dependency
69
+ name: rspec
70
+ prerelease: false
71
+ requirement: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ segments:
77
+ - 1
78
+ - 3
79
+ - 0
80
+ version: 1.3.0
81
+ type: :development
82
+ version_requirements: *id004
68
83
  description: CouchRest provides a simple interface on top of CouchDB's RESTful HTTP API, as well as including some utility scripts for managing views and attachments.
69
84
  email: jchris@apache.org
70
85
  executables: []
@@ -76,6 +91,9 @@ extra_rdoc_files:
76
91
  - README.md
77
92
  - THANKS.md
78
93
  files:
94
+ - .gitignore
95
+ - Gemfile
96
+ - Gemfile.lock
79
97
  - LICENSE
80
98
  - README.md
81
99
  - Rakefile
@@ -92,6 +110,7 @@ files:
92
110
  - examples/word_count/word_count_query.rb
93
111
  - examples/word_count/word_count_views.rb
94
112
  - history.txt
113
+ - init.rb
95
114
  - lib/couchrest.rb
96
115
  - lib/couchrest/commands/generate.rb
97
116
  - lib/couchrest/commands/push.rb
@@ -108,6 +127,7 @@ files:
108
127
  - lib/couchrest/rest_api.rb
109
128
  - lib/couchrest/server.rb
110
129
  - lib/couchrest/support/inheritable_attributes.rb
130
+ - spec/.gitignore
111
131
  - spec/couchrest/couchrest_spec.rb
112
132
  - spec/couchrest/database_spec.rb
113
133
  - spec/couchrest/design_spec.rb
@@ -147,11 +167,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
167
  required_rubygems_version: !ruby/object:Gem::Requirement
148
168
  none: false
149
169
  requirements:
150
- - - ">="
170
+ - - ">"
151
171
  - !ruby/object:Gem::Version
152
172
  segments:
153
- - 0
154
- version: "0"
173
+ - 1
174
+ - 3
175
+ - 1
176
+ version: 1.3.1
155
177
  requirements: []
156
178
 
157
179
  rubyforge_project:
@@ -159,15 +181,5 @@ rubygems_version: 1.3.7
159
181
  signing_key:
160
182
  specification_version: 3
161
183
  summary: Lean and RESTful interface to CouchDB.
162
- test_files:
163
- - spec/spec_helper.rb
164
- - spec/couchrest/couchrest_spec.rb
165
- - spec/couchrest/server_spec.rb
166
- - spec/couchrest/document_spec.rb
167
- - spec/couchrest/design_spec.rb
168
- - spec/couchrest/database_spec.rb
169
- - spec/couchrest/helpers/pager_spec.rb
170
- - spec/couchrest/helpers/streamer_spec.rb
171
- - examples/word_count/word_count_views.rb
172
- - examples/word_count/word_count_query.rb
173
- - examples/word_count/word_count.rb
184
+ test_files: []
185
+