couchrest_model 1.1.2 → 1.2.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/README.md +8 -2
  2. data/VERSION +1 -1
  3. data/couchrest_model.gemspec +2 -1
  4. data/history.md +8 -0
  5. data/lib/couchrest/model/base.rb +0 -20
  6. data/lib/couchrest/model/configuration.rb +2 -0
  7. data/lib/couchrest/model/core_extensions/time_parsing.rb +35 -9
  8. data/lib/couchrest/model/designs/design.rb +182 -0
  9. data/lib/couchrest/model/designs/view.rb +91 -48
  10. data/lib/couchrest/model/designs.rb +72 -19
  11. data/lib/couchrest/model/document_queries.rb +15 -45
  12. data/lib/couchrest/model/properties.rb +43 -2
  13. data/lib/couchrest/model/proxyable.rb +20 -54
  14. data/lib/couchrest/model/typecast.rb +1 -1
  15. data/lib/couchrest/model/validations/uniqueness.rb +7 -6
  16. data/lib/couchrest_model.rb +1 -5
  17. data/spec/fixtures/models/article.rb +22 -20
  18. data/spec/fixtures/models/base.rb +15 -7
  19. data/spec/fixtures/models/course.rb +7 -4
  20. data/spec/fixtures/models/project.rb +4 -1
  21. data/spec/fixtures/models/sale_entry.rb +5 -3
  22. data/spec/unit/base_spec.rb +51 -5
  23. data/spec/unit/core_extensions/time_parsing.rb +41 -0
  24. data/spec/unit/designs/design_spec.rb +291 -0
  25. data/spec/unit/designs/view_spec.rb +135 -40
  26. data/spec/unit/designs_spec.rb +341 -30
  27. data/spec/unit/dirty_spec.rb +67 -0
  28. data/spec/unit/inherited_spec.rb +2 -2
  29. data/spec/unit/property_protection_spec.rb +3 -1
  30. data/spec/unit/property_spec.rb +43 -3
  31. data/spec/unit/proxyable_spec.rb +57 -98
  32. data/spec/unit/subclass_spec.rb +14 -5
  33. data/spec/unit/validations_spec.rb +14 -12
  34. metadata +172 -129
  35. data/lib/couchrest/model/class_proxy.rb +0 -135
  36. data/lib/couchrest/model/collection.rb +0 -273
  37. data/lib/couchrest/model/design_doc.rb +0 -115
  38. data/lib/couchrest/model/support/couchrest_design.rb +0 -33
  39. data/lib/couchrest/model/views.rb +0 -148
  40. data/spec/unit/class_proxy_spec.rb +0 -167
  41. data/spec/unit/collection_spec.rb +0 -86
  42. data/spec/unit/design_doc_spec.rb +0 -212
  43. data/spec/unit/view_spec.rb +0 -352
metadata CHANGED
@@ -1,15 +1,10 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: couchrest_model
3
- version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease:
6
- segments:
7
- - 1
8
- - 1
9
- - 2
10
- version: 1.1.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.0.beta
5
+ prerelease: 6
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - J. Chris Anderson
14
9
  - Matt Aimonetti
15
10
  - Marcos Tapajos
@@ -18,131 +13,147 @@ authors:
18
13
  autorequire:
19
14
  bindir: bin
20
15
  cert_chain: []
21
-
22
- date: 2011-07-23 00:00:00 +02:00
23
- default_executable:
24
- dependencies:
25
- - !ruby/object:Gem::Dependency
16
+ date: 2012-06-08 00:00:00.000000000 Z
17
+ dependencies:
18
+ - !ruby/object:Gem::Dependency
26
19
  name: couchrest
27
- prerelease: false
28
- requirement: &id001 !ruby/object:Gem::Requirement
20
+ requirement: !ruby/object:Gem::Requirement
29
21
  none: false
30
- requirements:
22
+ requirements:
31
23
  - - ~>
32
- - !ruby/object:Gem::Version
33
- hash: 23
34
- segments:
35
- - 1
36
- - 1
37
- - 2
24
+ - !ruby/object:Gem::Version
38
25
  version: 1.1.2
39
26
  type: :runtime
40
- version_requirements: *id001
41
- - !ruby/object:Gem::Dependency
42
- name: mime-types
43
27
  prerelease: false
44
- requirement: &id002 !ruby/object:Gem::Requirement
28
+ version_requirements: !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.2
34
+ - !ruby/object:Gem::Dependency
35
+ name: mime-types
36
+ requirement: !ruby/object:Gem::Requirement
45
37
  none: false
46
- requirements:
38
+ requirements:
47
39
  - - ~>
48
- - !ruby/object:Gem::Version
49
- hash: 17
50
- segments:
51
- - 1
52
- - 15
53
- version: "1.15"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.15'
54
42
  type: :runtime
55
- version_requirements: *id002
56
- - !ruby/object:Gem::Dependency
57
- name: activemodel
58
43
  prerelease: false
59
- requirement: &id003 !ruby/object:Gem::Requirement
44
+ version_requirements: !ruby/object:Gem::Requirement
60
45
  none: false
61
- requirements:
46
+ requirements:
62
47
  - - ~>
63
- - !ruby/object:Gem::Version
64
- hash: 7
65
- segments:
66
- - 3
67
- - 0
68
- version: "3.0"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.15'
50
+ - !ruby/object:Gem::Dependency
51
+ name: activemodel
52
+ requirement: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ version: 3.1.0
69
58
  type: :runtime
70
- version_requirements: *id003
71
- - !ruby/object:Gem::Dependency
72
- name: tzinfo
73
59
  prerelease: false
74
- requirement: &id004 !ruby/object:Gem::Requirement
60
+ version_requirements: !ruby/object:Gem::Requirement
75
61
  none: false
76
- requirements:
62
+ requirements:
77
63
  - - ~>
78
- - !ruby/object:Gem::Version
79
- hash: 63
80
- segments:
81
- - 0
82
- - 3
83
- - 22
64
+ - !ruby/object:Gem::Version
65
+ version: 3.1.0
66
+ - !ruby/object:Gem::Dependency
67
+ name: tzinfo
68
+ requirement: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ~>
72
+ - !ruby/object:Gem::Version
84
73
  version: 0.3.22
85
74
  type: :runtime
86
- version_requirements: *id004
87
- - !ruby/object:Gem::Dependency
88
- name: rspec
89
75
  prerelease: false
90
- requirement: &id005 !ruby/object:Gem::Requirement
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ~>
80
+ - !ruby/object:Gem::Version
81
+ version: 0.3.22
82
+ - !ruby/object:Gem::Dependency
83
+ name: rspec
84
+ requirement: !ruby/object:Gem::Requirement
91
85
  none: false
92
- requirements:
86
+ requirements:
93
87
  - - ~>
94
- - !ruby/object:Gem::Version
95
- hash: 23
96
- segments:
97
- - 2
98
- - 6
99
- - 0
88
+ - !ruby/object:Gem::Version
100
89
  version: 2.6.0
101
90
  type: :development
102
- version_requirements: *id005
103
- - !ruby/object:Gem::Dependency
104
- name: json
105
91
  prerelease: false
106
- requirement: &id006 !ruby/object:Gem::Requirement
92
+ version_requirements: !ruby/object:Gem::Requirement
107
93
  none: false
108
- requirements:
94
+ requirements:
109
95
  - - ~>
110
- - !ruby/object:Gem::Version
111
- hash: 1
112
- segments:
113
- - 1
114
- - 5
115
- - 1
96
+ - !ruby/object:Gem::Version
97
+ version: 2.6.0
98
+ - !ruby/object:Gem::Dependency
99
+ name: json
100
+ requirement: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ~>
104
+ - !ruby/object:Gem::Version
116
105
  version: 1.5.1
117
106
  type: :development
118
- version_requirements: *id006
119
- - !ruby/object:Gem::Dependency
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ~>
112
+ - !ruby/object:Gem::Version
113
+ version: 1.5.1
114
+ - !ruby/object:Gem::Dependency
120
115
  name: rack-test
116
+ requirement: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: 0.5.7
122
+ type: :development
121
123
  prerelease: false
122
- requirement: &id007 !ruby/object:Gem::Requirement
124
+ version_requirements: !ruby/object:Gem::Requirement
123
125
  none: false
124
- requirements:
125
- - - ">="
126
- - !ruby/object:Gem::Version
127
- hash: 5
128
- segments:
129
- - 0
130
- - 5
131
- - 7
126
+ requirements:
127
+ - - ! '>='
128
+ - !ruby/object:Gem::Version
132
129
  version: 0.5.7
130
+ - !ruby/object:Gem::Dependency
131
+ name: rake
132
+ requirement: !ruby/object:Gem::Requirement
133
+ none: false
134
+ requirements:
135
+ - - ! '>='
136
+ - !ruby/object:Gem::Version
137
+ version: 0.8.0
133
138
  type: :development
134
- version_requirements: *id007
135
- description: CouchRest Model provides aditional features to the standard CouchRest Document class such as properties, view designs, associations, callbacks, typecasting and validations.
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: 0.8.0
146
+ description: CouchRest Model provides aditional features to the standard CouchRest
147
+ Document class such as properties, view designs, associations, callbacks, typecasting
148
+ and validations.
136
149
  email: jchris@apache.org
137
150
  executables: []
138
-
139
151
  extensions: []
140
-
141
- extra_rdoc_files:
152
+ extra_rdoc_files:
142
153
  - LICENSE
143
154
  - README.md
144
155
  - THANKS.md
145
- files:
156
+ files:
146
157
  - .gitignore
147
158
  - .rspec
148
159
  - Gemfile
@@ -162,14 +173,12 @@ files:
162
173
  - lib/couchrest/model/casted_array.rb
163
174
  - lib/couchrest/model/casted_by.rb
164
175
  - lib/couchrest/model/casted_hash.rb
165
- - lib/couchrest/model/class_proxy.rb
166
- - lib/couchrest/model/collection.rb
167
176
  - lib/couchrest/model/configuration.rb
168
177
  - lib/couchrest/model/connection.rb
169
178
  - lib/couchrest/model/core_extensions/hash.rb
170
179
  - lib/couchrest/model/core_extensions/time_parsing.rb
171
- - lib/couchrest/model/design_doc.rb
172
180
  - lib/couchrest/model/designs.rb
181
+ - lib/couchrest/model/designs/design.rb
173
182
  - lib/couchrest/model/designs/view.rb
174
183
  - lib/couchrest/model/dirty.rb
175
184
  - lib/couchrest/model/document_queries.rb
@@ -182,13 +191,11 @@ files:
182
191
  - lib/couchrest/model/property_protection.rb
183
192
  - lib/couchrest/model/proxyable.rb
184
193
  - lib/couchrest/model/support/couchrest_database.rb
185
- - lib/couchrest/model/support/couchrest_design.rb
186
194
  - lib/couchrest/model/typecast.rb
187
195
  - lib/couchrest/model/validations.rb
188
196
  - lib/couchrest/model/validations/casted_model.rb
189
197
  - lib/couchrest/model/validations/locale/en.yml
190
198
  - lib/couchrest/model/validations/uniqueness.rb
191
- - lib/couchrest/model/views.rb
192
199
  - lib/couchrest/railtie.rb
193
200
  - lib/couchrest_model.rb
194
201
  - lib/rails/generators/couchrest_model.rb
@@ -230,12 +237,10 @@ files:
230
237
  - spec/unit/attachment_spec.rb
231
238
  - spec/unit/base_spec.rb
232
239
  - spec/unit/casted_spec.rb
233
- - spec/unit/class_proxy_spec.rb
234
- - spec/unit/collection_spec.rb
235
240
  - spec/unit/configuration_spec.rb
236
241
  - spec/unit/connection_spec.rb
237
242
  - spec/unit/core_extensions/time_parsing.rb
238
- - spec/unit/design_doc_spec.rb
243
+ - spec/unit/designs/design_spec.rb
239
244
  - spec/unit/designs/view_spec.rb
240
245
  - spec/unit/designs_spec.rb
241
246
  - spec/unit/dirty_spec.rb
@@ -248,42 +253,80 @@ files:
248
253
  - spec/unit/subclass_spec.rb
249
254
  - spec/unit/typecast_spec.rb
250
255
  - spec/unit/validations_spec.rb
251
- - spec/unit/view_spec.rb
252
- has_rdoc: true
253
256
  homepage: http://github.com/couchrest/couchrest_model
254
257
  licenses: []
255
-
256
258
  post_install_message:
257
259
  rdoc_options: []
258
-
259
- require_paths:
260
+ require_paths:
260
261
  - lib
261
- required_ruby_version: !ruby/object:Gem::Requirement
262
+ required_ruby_version: !ruby/object:Gem::Requirement
262
263
  none: false
263
- requirements:
264
- - - ">="
265
- - !ruby/object:Gem::Version
266
- hash: 3
267
- segments:
264
+ requirements:
265
+ - - ! '>='
266
+ - !ruby/object:Gem::Version
267
+ version: '0'
268
+ segments:
268
269
  - 0
269
- version: "0"
270
- required_rubygems_version: !ruby/object:Gem::Requirement
270
+ hash: -3604299647194247287
271
+ required_rubygems_version: !ruby/object:Gem::Requirement
271
272
  none: false
272
- requirements:
273
- - - ">"
274
- - !ruby/object:Gem::Version
275
- hash: 25
276
- segments:
277
- - 1
278
- - 3
279
- - 1
273
+ requirements:
274
+ - - ! '>'
275
+ - !ruby/object:Gem::Version
280
276
  version: 1.3.1
281
277
  requirements: []
282
-
283
278
  rubyforge_project:
284
- rubygems_version: 1.6.2
279
+ rubygems_version: 1.8.24
285
280
  signing_key:
286
281
  specification_version: 3
287
282
  summary: Extends the CouchRest Document for advanced modelling.
288
- test_files: []
289
-
283
+ test_files:
284
+ - spec/fixtures/attachments/README
285
+ - spec/fixtures/attachments/couchdb.png
286
+ - spec/fixtures/attachments/test.html
287
+ - spec/fixtures/config/couchdb.yml
288
+ - spec/fixtures/models/article.rb
289
+ - spec/fixtures/models/base.rb
290
+ - spec/fixtures/models/card.rb
291
+ - spec/fixtures/models/cat.rb
292
+ - spec/fixtures/models/client.rb
293
+ - spec/fixtures/models/course.rb
294
+ - spec/fixtures/models/event.rb
295
+ - spec/fixtures/models/invoice.rb
296
+ - spec/fixtures/models/key_chain.rb
297
+ - spec/fixtures/models/membership.rb
298
+ - spec/fixtures/models/person.rb
299
+ - spec/fixtures/models/project.rb
300
+ - spec/fixtures/models/question.rb
301
+ - spec/fixtures/models/sale_entry.rb
302
+ - spec/fixtures/models/sale_invoice.rb
303
+ - spec/fixtures/models/service.rb
304
+ - spec/fixtures/models/user.rb
305
+ - spec/fixtures/views/lib.js
306
+ - spec/fixtures/views/test_view/lib.js
307
+ - spec/fixtures/views/test_view/only-map.js
308
+ - spec/fixtures/views/test_view/test-map.js
309
+ - spec/fixtures/views/test_view/test-reduce.js
310
+ - spec/functional/validations_spec.rb
311
+ - spec/spec_helper.rb
312
+ - spec/unit/active_model_lint_spec.rb
313
+ - spec/unit/assocations_spec.rb
314
+ - spec/unit/attachment_spec.rb
315
+ - spec/unit/base_spec.rb
316
+ - spec/unit/casted_spec.rb
317
+ - spec/unit/configuration_spec.rb
318
+ - spec/unit/connection_spec.rb
319
+ - spec/unit/core_extensions/time_parsing.rb
320
+ - spec/unit/designs/design_spec.rb
321
+ - spec/unit/designs/view_spec.rb
322
+ - spec/unit/designs_spec.rb
323
+ - spec/unit/dirty_spec.rb
324
+ - spec/unit/embeddable_spec.rb
325
+ - spec/unit/inherited_spec.rb
326
+ - spec/unit/persistence_spec.rb
327
+ - spec/unit/property_protection_spec.rb
328
+ - spec/unit/property_spec.rb
329
+ - spec/unit/proxyable_spec.rb
330
+ - spec/unit/subclass_spec.rb
331
+ - spec/unit/typecast_spec.rb
332
+ - spec/unit/validations_spec.rb
@@ -1,135 +0,0 @@
1
- module CouchRest
2
- module Model
3
- module ClassProxy
4
-
5
- def self.included(base)
6
- base.extend(ClassMethods)
7
- end
8
-
9
- module ClassMethods
10
-
11
- # Return a proxy object which represents a model class on a
12
- # chosen database instance. This allows you to DRY operations
13
- # where a database is chosen dynamically.
14
- #
15
- # ==== Example:
16
- #
17
- # db = CouchRest::Database.new(...)
18
- # articles = Article.on(db)
19
- #
20
- # articles.all { ... }
21
- # articles.by_title { ... }
22
- #
23
- # u = articles.get("someid")
24
- #
25
- # u = articles.new(:title => "I like plankton")
26
- # u.save # saved on the correct database
27
-
28
- def on(database)
29
- Proxy.new(self, database)
30
- end
31
- end
32
-
33
- class Proxy #:nodoc:
34
- def initialize(klass, database)
35
- @klass = klass
36
- @database = database
37
- end
38
-
39
- # Base
40
-
41
- def new(*args)
42
- doc = @klass.new(*args)
43
- doc.database = @database
44
- doc
45
- end
46
-
47
- def method_missing(m, *args, &block)
48
- if has_view?(m)
49
- query = args.shift || {}
50
- return view(m, query, *args, &block)
51
- elsif m.to_s =~ /^find_(by_.+)/
52
- view_name = $1
53
- if has_view?(view_name)
54
- return first_from_view(view_name, *args)
55
- end
56
- end
57
- super
58
- end
59
-
60
- # DocumentQueries
61
-
62
- def all(opts = {}, &block)
63
- docs = @klass.all({:database => @database}.merge(opts), &block)
64
- docs.each { |doc| doc.database = @database if doc.respond_to?(:database) } if docs
65
- docs
66
- end
67
-
68
- def count(opts = {}, &block)
69
- @klass.all({:database => @database, :raw => true, :limit => 0}.merge(opts), &block)['total_rows']
70
- end
71
-
72
- def first(opts = {})
73
- doc = @klass.first({:database => @database}.merge(opts))
74
- doc.database = @database if doc && doc.respond_to?(:database)
75
- doc
76
- end
77
-
78
- def last(opts = {})
79
- doc = @klass.last({:database => @database}.merge(opts))
80
- doc.database = @database if doc && doc.respond_to?(:database)
81
- doc
82
- end
83
-
84
- def get(id)
85
- doc = @klass.get(id, @database)
86
- doc.database = @database if doc && doc.respond_to?(:database)
87
- doc
88
- end
89
- alias :find :get
90
-
91
- def get!(id)
92
- doc = @klass.get!(id, @database)
93
- doc.database = @database if doc && doc.respond_to?(:database)
94
- doc
95
- end
96
- alias :find! :get!
97
-
98
- # Views
99
-
100
- def has_view?(view)
101
- @klass.has_view?(view)
102
- end
103
-
104
- def view(name, query={}, &block)
105
- docs = @klass.view(name, {:database => @database}.merge(query), &block)
106
- docs.each { |doc| doc.database = @database if doc.respond_to?(:database) } if docs
107
- docs
108
- end
109
-
110
- def first_from_view(name, *args)
111
- # add to first hash available, or add to end
112
- (args.last.is_a?(Hash) ? args.last : (args << {}).last)[:database] = @database
113
- doc = @klass.first_from_view(name, *args)
114
- doc.database = @database if doc && doc.respond_to?(:database)
115
- doc
116
- end
117
-
118
- # DesignDoc
119
-
120
- def design_doc
121
- @klass.design_doc
122
- end
123
-
124
- def refresh_design_doc
125
- @klass.refresh_design_doc(@database)
126
- end
127
-
128
- def save_design_doc
129
- @klass.save_design_doc(@database)
130
- end
131
-
132
- end
133
- end
134
- end
135
- end