couchrest_model 1.0.0.beta8 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/.gitignore +9 -0
  2. data/{spec/spec.opts → .rspec} +0 -1
  3. data/Gemfile +4 -0
  4. data/Gemfile.lock +77 -0
  5. data/README.md +144 -57
  6. data/Rakefile +12 -43
  7. data/VERSION +1 -0
  8. data/couchrest_model.gemspec +35 -0
  9. data/history.txt +23 -1
  10. data/init.rb +1 -0
  11. data/lib/couchrest/model/associations.rb +17 -1
  12. data/lib/couchrest/model/base.rb +5 -5
  13. data/lib/couchrest/model/casted_model.rb +2 -2
  14. data/lib/couchrest/model/class_proxy.rb +6 -0
  15. data/lib/couchrest/model/collection.rb +3 -0
  16. data/lib/couchrest/model/configuration.rb +51 -0
  17. data/lib/couchrest/model/design_doc.rb +2 -5
  18. data/lib/couchrest/model/document_queries.rb +20 -3
  19. data/lib/couchrest/model/persistence.rb +15 -1
  20. data/lib/couchrest/model/properties.rb +97 -23
  21. data/lib/couchrest/model/property.rb +5 -4
  22. data/lib/couchrest/model/property_protection.rb +71 -0
  23. data/lib/couchrest/model/typecast.rb +12 -7
  24. data/lib/couchrest/model/view.rb +190 -0
  25. data/lib/couchrest/model/views.rb +3 -3
  26. data/lib/couchrest/model.rb +1 -1
  27. data/lib/couchrest/railtie.rb +3 -2
  28. data/lib/couchrest_model.rb +7 -14
  29. data/lib/rails/generators/couchrest_model/model/model_generator.rb +2 -1
  30. data/spec/.gitignore +1 -0
  31. data/spec/couchrest/base_spec.rb +3 -3
  32. data/spec/couchrest/casted_model_spec.rb +63 -49
  33. data/spec/couchrest/class_proxy_spec.rb +6 -0
  34. data/spec/couchrest/configuration_spec.rb +78 -0
  35. data/spec/couchrest/persistence_spec.rb +10 -4
  36. data/spec/couchrest/{attribute_protection_spec.rb → property_protection_spec.rb} +29 -2
  37. data/spec/couchrest/property_spec.rb +61 -0
  38. data/spec/couchrest/subclass_spec.rb +2 -2
  39. data/spec/couchrest/view_spec.rb +6 -0
  40. data/spec/fixtures/more/article.rb +1 -1
  41. data/spec/spec_helper.rb +4 -3
  42. metadata +96 -32
  43. data/lib/couchrest/model/attribute_protection.rb +0 -74
  44. data/lib/couchrest/model/attributes.rb +0 -75
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ .DS_Store
2
+ html/*
3
+ pkg
4
+ *.swp
5
+ .rvmrc
6
+ .bundle
7
+ couchdb.std*
8
+ *.*~
9
+
@@ -1,5 +1,4 @@
1
1
  --colour
2
2
  --format
3
3
  progress
4
- --loadby
5
4
  mtime
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+
2
+ source :rubygems
3
+ gemspec
4
+
data/Gemfile.lock ADDED
@@ -0,0 +1,77 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ couchrest_model (1.0.0)
5
+ activemodel (~> 3.0.0)
6
+ couchrest (~> 1.0.1)
7
+ mime-types (~> 1.15)
8
+ railties (~> 3.0.0)
9
+ rspec (>= 2.0.0)
10
+ tzinfo (~> 0.3.22)
11
+
12
+ GEM
13
+ remote: http://rubygems.org/
14
+ specs:
15
+ abstract (1.0.0)
16
+ actionpack (3.0.3)
17
+ activemodel (= 3.0.3)
18
+ activesupport (= 3.0.3)
19
+ builder (~> 2.1.2)
20
+ erubis (~> 2.6.6)
21
+ i18n (~> 0.4)
22
+ rack (~> 1.2.1)
23
+ rack-mount (~> 0.6.13)
24
+ rack-test (~> 0.5.6)
25
+ tzinfo (~> 0.3.23)
26
+ activemodel (3.0.3)
27
+ activesupport (= 3.0.3)
28
+ builder (~> 2.1.2)
29
+ i18n (~> 0.4)
30
+ activesupport (3.0.3)
31
+ builder (2.1.2)
32
+ couchrest (1.0.1)
33
+ json (>= 1.4.6)
34
+ mime-types (>= 1.15)
35
+ rest-client (>= 1.5.1)
36
+ diff-lcs (1.1.2)
37
+ erubis (2.6.6)
38
+ abstract (>= 1.0.0)
39
+ i18n (0.5.0)
40
+ json (1.4.6)
41
+ mime-types (1.16)
42
+ rack (1.2.1)
43
+ rack-mount (0.6.13)
44
+ rack (>= 1.0.0)
45
+ rack-test (0.5.7)
46
+ rack (>= 1.0)
47
+ railties (3.0.3)
48
+ actionpack (= 3.0.3)
49
+ activesupport (= 3.0.3)
50
+ rake (>= 0.8.7)
51
+ thor (~> 0.14.4)
52
+ rake (0.8.7)
53
+ rest-client (1.6.1)
54
+ mime-types (>= 1.16)
55
+ rspec (2.2.0)
56
+ rspec-core (~> 2.2)
57
+ rspec-expectations (~> 2.2)
58
+ rspec-mocks (~> 2.2)
59
+ rspec-core (2.3.0)
60
+ rspec-expectations (2.3.0)
61
+ diff-lcs (~> 1.1.2)
62
+ rspec-mocks (2.3.0)
63
+ thor (0.14.6)
64
+ tzinfo (0.3.23)
65
+
66
+ PLATFORMS
67
+ ruby
68
+
69
+ DEPENDENCIES
70
+ activemodel (~> 3.0.0)
71
+ couchrest (~> 1.0.1)
72
+ couchrest_model!
73
+ mime-types (~> 1.15)
74
+ rack-test (>= 0.5.7)
75
+ railties (~> 3.0.0)
76
+ rspec (>= 2.0.0)
77
+ tzinfo (~> 0.3.22)
data/README.md CHANGED
@@ -9,16 +9,13 @@ for validations and callbacks.
9
9
  If your project is still running Rails 2.3, you'll have to continue using ExtendedDocument as
10
10
  it is not possible to load ActiveModel into programs that do not use ActiveSupport 3.0.
11
11
 
12
- CouchRest Model only supports CouchDB 0.10.0 or newer.
12
+ CouchRest Model is only tested on CouchDB 1.0.0 or newer.
13
13
 
14
14
  ## Install
15
15
 
16
- ### From Gem
16
+ ### Gem
17
17
 
18
- CouchRest Model depends on Rails 3's ActiveModel which has not yet been released. You'll need to add
19
- `--pre` to the end of the gem install until the dependencies are stable:
20
-
21
- $ sudo gem install couchrest_model --pre
18
+ $ sudo gem install couchrest_model
22
19
 
23
20
  ### Bundler
24
21
 
@@ -31,7 +28,33 @@ but no guarantees!
31
28
 
32
29
  gem 'couchrest_model', :git => 'git://github.com/couchrest/couchrest_model.git'
33
30
 
34
-
31
+ ### Development
32
+
33
+ CouchRest Model now comes with a Gemfile to help with development. If you want to make changes to the code, download a copy then run:
34
+
35
+ bundle install
36
+
37
+ That should set everything up for `rake spec` to be run correctly. Update the couchrest_model.gemspec if your alterations
38
+ use different gems.
39
+
40
+ ## Generators
41
+
42
+ ### Model
43
+
44
+ $ rails generate model person --orm=couchrest_model
45
+
46
+ ## Useful links and extensions
47
+
48
+ Try some of these gems that add extra funcionality to couchrest_model:
49
+
50
+ * [memories](http://github.com/moonmaster9000/memories) - object versioning using attachments (Matt Parker)
51
+ * [couch_publish](http://github.com/moonmaster9000/couch_publish) - versioned state machine for draft and published documents (Matt Parker)
52
+ * [couch_photo](http://github.com/moonmaster9000/couch_photo) - attach images to documents with variations (Matt Parker)
53
+ * [copycouch](http://github.com/moonmaster9000/copycouch) - single document replication on documents (Matt Parker)
54
+ * [recloner](https://github.com/moonmaster9000/recloner) - clone documents easily (Matt Parker)
55
+
56
+ If you have an extension that you'd us to add to this list, please get in touch!
57
+
35
58
  ## General Usage
36
59
 
37
60
  require 'couchrest_model'
@@ -66,16 +89,14 @@ but no guarantees!
66
89
 
67
90
  ## Properties
68
91
 
69
- Only attributes with a property definition will be stored be CouchRest Model (as opposed
70
- to a normal CouchRest Document which will store everything). To help prevent confusion,
71
- a property should be considered as the definition of an attribute. An attribute must be associated
72
- with a property, but a property may not have any attributes associated if none have been set.
92
+ A property is the definition of an attribute, it describes what the attribute is called, how it should
93
+ be type casted and other options such as the default value. These replace your typical
94
+ `add_column` methods found in relational database migrations.
73
95
 
96
+ Attributes with a property definition will have setter and getter methods defined for them. Any other attibute
97
+ can be set in the same way you'd update a Hash, this funcionality is inherited from CouchRest Documents.
74
98
 
75
- In its simplest form, a property
76
- will only create a getter and setter passing all attribute data directly to the database. Assuming the attribute
77
- provided responds to `to_json`, there will not be any problems saving it, but when loading the
78
- data back it will either be a string, number, array, or hash:
99
+ Here are a few examples of the way properties are used:
79
100
 
80
101
  class Cat < CouchRest::Model::Base
81
102
  property :name
@@ -100,8 +121,7 @@ Properties create getters and setters similar to the following:
100
121
  write_attribute('name', value)
101
122
  end
102
123
 
103
- Properties can also have a type which
104
- will be used for casting data retrieved from CouchDB when the attribute is set:
124
+ Properties can also have a type which will be used for casting data retrieved from CouchDB when the attribute is set:
105
125
 
106
126
  class Cat < CouchRest::Model::Base
107
127
  property :name, String
@@ -115,7 +135,7 @@ will be used for casting data retrieved from CouchDB when the attribute is set:
115
135
  @cat.last_fed_at < 20.minutes.ago # True!
116
136
 
117
137
 
118
- Booleans or TrueClass will also create a getter with question mark at the end:
138
+ Boolean or TrueClass types will create a getter with question mark at the end:
119
139
 
120
140
  class Cat < CouchRest::Model::Base
121
141
  property :awake, TrueClass, :default => true
@@ -125,9 +145,8 @@ Booleans or TrueClass will also create a getter with question mark at the end:
125
145
 
126
146
  Adding the +:default+ option will ensure the attribute always has a value.
127
147
 
128
- Defining a property as read-only will mean that its value is set only when read from the
129
- database and that it will not have a setter method. You can however update a read-only
130
- attribute using the `write_attribute` method:
148
+ A read-only property will only have a getter method, and its value is set when the document
149
+ is read from the database. You can however update a read-only attribute using the `write_attribute` method:
131
150
 
132
151
  class Cat < CouchRest::Model::Base
133
152
  property :name, String
@@ -143,10 +162,23 @@ attribute using the `write_attribute` method:
143
162
  @cat.fall_off_balcony!
144
163
  @cat.lives # Now 8!
145
164
 
165
+ Mass assigning attributes is also possible in a similar fashion to ActiveRecord:
166
+
167
+ @cat.attributes = { :name => "Felix" }
168
+ @cat.save
169
+
170
+ Is the same as:
171
+
172
+ @cat.update_attributes(:name => "Felix")
173
+
174
+ By default, attributes without a property will not be updated via the `#attributes=` method. This provents useless data being passed to database, for example from an HTML form. However, if you would like truely
175
+ dynamic attributes, the `mass_assign_any_attribute` configuration option when set to true will
176
+ store everything you put into the `Base#attributes=` method.
177
+
146
178
 
147
179
  ## Property Arrays
148
180
 
149
- An attribute may also contain an array of data. CouchRest Model handles this, along
181
+ An attribute may contain an array of data. CouchRest Model handles this, along
150
182
  with casting, by defining the class of the child attributes inside an Array:
151
183
 
152
184
  class Cat < CouchRest::Model::Base
@@ -172,14 +204,14 @@ documents and retrieve them using the CastedModel module. Simply include the mod
172
204
  a Hash (or other model that responds to the [] and []= methods) and set any properties
173
205
  you'd like to use. For example:
174
206
 
175
- class CatToy << Hash
207
+ class CatToy < Hash
176
208
  include CouchRest::Model::CastedModel
177
209
 
178
210
  property :name, String
179
211
  property :purchased, Date
180
212
  end
181
213
 
182
- class Cat << CouchRest::Model::Base
214
+ class Cat < CouchRest::Model::Base
183
215
  property :name, String
184
216
  property :toys, [CatToy]
185
217
  end
@@ -188,17 +220,16 @@ you'd like to use. For example:
188
220
  @cat.toys.first.class == CatToy
189
221
  @cat.toys.first.name == 'mouse'
190
222
 
191
- Additionally, any hashes sent to the property will automatically be converted:
223
+ Any hashes sent to the property will automatically be converted:
192
224
 
193
225
  @cat.toys << {:name => 'catnip ball'}
194
226
  @cat.toys.last.is_a?(CatToy) # True!
195
227
 
196
- Of course, to use your own classes they *must* be defined before the parent uses them otherwise
228
+ To use your own classes they *must* be defined before the parent uses them otherwise
197
229
  Ruby will bring up a missing constant error. To avoid this, or if you have a really simple array of data
198
- you'd like to model, the latest version of CouchRest Model (> 1.0.0) supports creating
199
- anonymous classes:
230
+ you'd like to model, CouchRest Model supports creating anonymous classes:
200
231
 
201
- class Cat << CouchRest::Model::Base
232
+ class Cat < CouchRest::Model::Base
202
233
  property :name, String
203
234
 
204
235
  property :toys do |toy|
@@ -211,7 +242,7 @@ anonymous classes:
211
242
  @cat.toys.last.rating == 5
212
243
  @cat.toys.last.name == 'catnip ball'
213
244
 
214
- Using this method of anonymous classes will *only* create arrays of objects.
245
+ Anonymous classes will *only* create arrays of objects.
215
246
 
216
247
 
217
248
  ## Assocations
@@ -222,14 +253,67 @@ Two types at the moment:
222
253
 
223
254
  collection_of :tags
224
255
 
225
- TODO: Document properly!
256
+ This is a somewhat controvesial feature of CouchRest Model that some document database purists may fringe at. CouchDB does not yet povide many features to support relationships between documents but the fact of that matter is that its a very useful paradigm for modelling data systems.
257
+
258
+ In the near future we hope to add support for a `has_many` relationship that takes of the _Linked Documents_ feature that arrived in CouchDB 0.11.
259
+
260
+ ### Belongs To
261
+
262
+ Creates a property in the document with `_id` added to the end of the name of the foreign model with getter and setter methods to access the model.
263
+
264
+ Example:
265
+
266
+ class Cat < CouchRest::Model::Base
267
+ belongs_to :mother
268
+ property :name
269
+ end
270
+
271
+ kitty = Cat.new(:name => "Felix")
272
+ kitty.mother = Mother.find_by_name('Sophie')
273
+
274
+ Providing a object to the setter, `mother` in the example will automagically update the `mother_id` attribute. Retrieving the data later is just as expected:
275
+
276
+ kitty = Cat.find_by_name "Felix"
277
+ kitty.mother.name == 'Sophie'
278
+
279
+ Belongs_to accepts a few options to add a bit more felxibility:
280
+
281
+ * `:class_name` - the camel case string name of the class used to load the model.
282
+ * `:foreign_key` - the name of the property to use instead of the attribute name with `_id` on the end.
283
+ * `:proxy` - a string that when evaluated provides a proxy model that responds to `#get`.
284
+
285
+ The last option, `:proxy` is a feature currently in testing that allows objects to be loaded from a proxy class, such as `ClassProxy`. For example:
286
+
287
+ class Invoice < CouchRest::Model::Base
288
+ attr_accessor :company
289
+ belongs_to :project, :proxy => 'self.company.projects'
290
+ end
291
+
292
+ A project instance in this scenario would need to be loaded by calling `#get(project_id)` on `self.company.projects` in the scope of an instance of the Invoice. We hope to document and work on this powerful feature in the near future.
293
+
294
+
295
+ ### Collection Of
226
296
 
297
+ A collection_of relationship is much like belongs_to except that rather than just one foreign key, an array of foreign keys can be stored. This is one of the great features of a document database. This relationship uses a proxy object to automatically update two arrays; one containing the objects being used, and a second with the foreign keys used to the find them.
298
+
299
+ The best example of this in use is with Labels:
300
+
301
+ class Invoice < CouchRest::Model::Base
302
+ collection_of :labels
303
+ end
304
+
305
+ invoice = Invoice.new
306
+ invoice.labels << Label.get('xyz')
307
+ invoice.labels << Label.get('abc')
308
+
309
+ invoice.labels.map{|l| l.name} # produces ['xyz', 'abc']
310
+
311
+ See the belongs_to relationship for the options that can be used. Note that this isn't especially efficient, a `get` is performed for each model in the array. As with a has_many relationship, we hope to be able to take advantage of the Linked Documents feature to avoid multiple requests.
227
312
 
228
313
 
229
314
  ## Validations
230
315
 
231
- CouchRest Model automatically includes the new ActiveModel validations, so they should work just as the traditional Rails
232
- validations. For more details, please see the ActiveModel::Validations documentation.
316
+ CouchRest Model automatically includes the new ActiveModel validations, so they should work just as the traditional Rails validations. For more details, please see the ActiveModel::Validations documentation.
233
317
 
234
318
  CouchRest Model adds the possibility to check the uniqueness of attributes using the `validates_uniqueness_of` class method, for example:
235
319
 
@@ -246,9 +330,7 @@ you'd like to avoid the typical RestClient Conflict error:
246
330
  unique_id :code
247
331
  validates_uniqueness_of :code, :view => 'all'
248
332
 
249
- Given that the uniqueness check performs a request to the database, it is also possible
250
- to include a @:proxy@ parameter. This allows you to
251
- call a method on the document and provide an alternate proxy object.
333
+ Given that the uniqueness check performs a request to the database, it is also possible to include a `:proxy` parameter. This allows you to call a method on the document and provide an alternate proxy object.
252
334
 
253
335
  Examples:
254
336
 
@@ -259,8 +341,7 @@ Examples:
259
341
  validates_uniqueness_of :title, :proxy => 'company.people'
260
342
 
261
343
 
262
- A really interesting use of +:proxy+ and +:view+ together could be where
263
- you'd like to ensure the ID is unique between several types of document. For example:
344
+ A really interesting use of `:proxy` and `:view` together could be where you'd like to ensure the ID is unique between several types of document. For example:
264
345
 
265
346
  class Product < CouchRest::Model::Base
266
347
  property :code
@@ -285,40 +366,46 @@ you'd like to ensure the ID is unique between several types of document. For exa
285
366
  Pretty cool!
286
367
 
287
368
 
369
+ ## Configuration
288
370
 
289
- ## Notable Issues
371
+ CouchRest Model supports a few configuration options. These can be set either for the whole Model code
372
+ base or for a specific model of your chosing. To configure globally, provide something similar to the
373
+ following in your projects loading code:
290
374
 
291
- CouchRest Model uses active_support for some of its internals. Ensure you have a stable active support gem installed
292
- or at least 3.0.0.beta4.
375
+ CouchRest::Model::Base.configure do |config|
376
+ config.mass_assign_any_attribute = true
377
+ config.model_type_key = 'couchrest-type'
378
+ end
293
379
 
294
- JSON gem versions 1.4.X are kown to cause problems with stack overflows and general badness. Version 1.2.4 appears to work fine.
380
+ To set for a specific model:
295
381
 
296
- ## Ruby on Rails
382
+ class Cat < CouchRest::Model::Base
383
+ mass_assign_any_attribute true
384
+ end
297
385
 
298
- CouchRest Model is compatible with rails and provides some ActiveRecord-like methods.
386
+ Options currently avilable are:
299
387
 
300
- The CouchRest companion rails project
301
- [http://github.com/hpoydar/couchrest-rails](http://github.com/hpoydar/couchrest-rails) is great
302
- for provided default connection details for your database. At the time of writting however it
303
- does not provide explicit support for CouchRest Model.
388
+ * `mass_assign_any_attribute` - false by default, when true any attribute may be updated via the update_attributes or attributes= methods.
389
+ * `model_type_key` - 'couchrest-type' by default, is the name of property that holds the class name of each CouchRest Model.
304
390
 
305
- CouchRest Model and the original CouchRest ExtendedDocument do not share the same namespace,
306
- as such you should not have any problems using them both at the same time. This might
307
- help with migrations.
391
+
392
+ ## Notable Issues
393
+
394
+ None at the moment...
308
395
 
309
396
 
310
- ### Rails 3.0
397
+ ## Ruby on Rails
398
+
399
+ CouchRest Model is compatible with rails and provides some ActiveRecord-like methods.
311
400
 
312
- In your Gemfile require the gem with a simple line:
401
+ The CouchRest companion rails project [http://github.com/hpoydar/couchrest-rails](http://github.com/hpoydar/couchrest-rails) is great for providing default connection details for your database. At the time of writting however it does not provide explicit support for CouchRest Model.
313
402
 
314
- gem "couchrest_model"
403
+ CouchRest Model and the original CouchRest ExtendedDocument do not share the same namespace, as such you should not have any problems using them both at the same time. This might help with migrations.
315
404
 
316
405
 
317
406
  ## Testing
318
407
 
319
- The most complete documentation is the spec/ directory. To validate your
320
- CouchRest install, from the project root directory run `rake`, or `autotest`
321
- (requires RSpec and optionally ZenTest for autotest support).
408
+ The most complete documentation is the spec/ directory. To validate your CouchRest install, from the project root directory run `rake`, or `autotest` (requires RSpec and optionally ZenTest for autotest support).
322
409
 
323
410
  ## Docs
324
411
 
data/Rakefile CHANGED
@@ -1,54 +1,23 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler::GemHelper.install_tasks
4
+
1
5
  require 'rake'
2
6
  require "rake/rdoctask"
3
7
 
4
- $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
5
- require 'couchrest_model'
6
-
7
- begin
8
- require 'spec/rake/spectask'
9
- rescue LoadError
10
- puts <<-EOS
11
- To use rspec for testing you must install rspec gem:
12
- gem install rspec
13
- EOS
14
- exit(0)
15
- end
16
-
17
- begin
18
- require 'jeweler'
19
- Jeweler::Tasks.new do |gemspec|
20
- gemspec.name = "couchrest_model"
21
- gemspec.summary = "Extends the CouchRest Document for advanced modelling."
22
- gemspec.description = "CouchRest Model provides aditional features to the standard CouchRest Document class such as properties, view designs, associations, callbacks, typecasting and validations."
23
- gemspec.email = "jchris@apache.org"
24
- gemspec.homepage = "http://github.com/couchrest/couchrest_model"
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}/**/*"] - Dir["spec/tmp"]
28
- gemspec.has_rdoc = true
29
- gemspec.add_dependency("couchrest", "~> 1.0.0")
30
- gemspec.add_dependency("mime-types", "~> 1.15")
31
- gemspec.add_dependency("activesupport", "~> 2.3.5")
32
- gemspec.add_dependency("activemodel", "~> 3.0.0.beta4")
33
- gemspec.add_dependency("tzinfo", "~> 0.3.22")
34
- gemspec.version = CouchRest::Model::VERSION
35
- gemspec.date = Time.now.strftime("%Y-%m-%d")
36
- gemspec.require_path = "lib"
37
- end
38
- rescue LoadError
39
- puts "Jeweler not available. Install it with: gem install jeweler"
40
- end
8
+ require 'rspec'
9
+ require 'rspec/core/rake_task'
41
10
 
42
11
  desc "Run all specs"
43
- Spec::Rake::SpecTask.new('spec') do |t|
44
- t.spec_opts = ["--color"]
45
- t.spec_files = FileList['spec/**/*_spec.rb']
12
+ Rspec::Core::RakeTask.new(:spec) do |spec|
13
+ spec.rspec_opts = ["--color"]
14
+ spec.pattern = 'spec/**/*_spec.rb'
46
15
  end
47
16
 
48
17
  desc "Print specdocs"
49
- Spec::Rake::SpecTask.new(:doc) do |t|
50
- t.spec_opts = ["--format", "specdoc"]
51
- t.spec_files = FileList['spec/*_spec.rb']
18
+ Rspec::Core::RakeTask.new(:doc) do |spec|
19
+ spec.rspec_opts = ["--format", "specdoc"]
20
+ spec.pattern = 'spec/*_spec.rb'
52
21
  end
53
22
 
54
23
  desc "Generate the rdoc"
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{couchrest_model}
5
+ s.version = "1.0.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["J. Chris Anderson", "Matt Aimonetti", "Marcos Tapajos", "Will Leinweber", "Sam Lown"]
9
+ s.date = %q{2011-01-16}
10
+ s.description = %q{CouchRest Model provides aditional features to the standard CouchRest Document class such as properties, view designs, associations, callbacks, typecasting and validations.}
11
+ s.email = %q{jchris@apache.org}
12
+ s.extra_rdoc_files = [
13
+ "LICENSE",
14
+ "README.md",
15
+ "THANKS.md"
16
+ ]
17
+ s.homepage = %q{http://github.com/couchrest/couchrest_model}
18
+ s.rubygems_version = %q{1.3.7}
19
+ s.summary = %q{Extends the CouchRest Document for advanced modelling.}
20
+
21
+ s.files = `git ls-files`.split("\n")
22
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
+ s.require_paths = ["lib"]
25
+
26
+ s.add_dependency(%q<couchrest>, "~> 1.0.1")
27
+ s.add_dependency(%q<mime-types>, "~> 1.15")
28
+ s.add_dependency(%q<activemodel>, "~> 3.0.0")
29
+ s.add_dependency(%q<tzinfo>, "~> 0.3.22")
30
+ s.add_dependency(%q<railties>, "~> 3.0.0")
31
+ s.add_dependency(%q<rspec>, ">= 2.0.0")
32
+ s.add_development_dependency(%q<rspec>, ">= 2.0.0")
33
+ s.add_development_dependency(%q<rack-test>, ">= 0.5.7")
34
+ end
35
+
data/history.txt CHANGED
@@ -1,10 +1,32 @@
1
- == Next Version
1
+ == CouchRest Model 1.0.0
2
2
 
3
3
  * Major enhancements
4
+ * Support for configuration module and "model_type_key" option for overriding model's type key
5
+ * Added "mass_assign_any_attribute" configuration option to allow setting anything via the attribute= method.
6
+
7
+ * Minor enhancements
8
+ * Fixing find("") issue (thanks epochwolf)
9
+ * Altered protected attributes so that hash provided to #attributes= is not modified
10
+ * Altering typecasting for floats to better handle commas and points
11
+ * Fixing the lame pagination bug where database url (and pass!!) were included in view requests (Thanks James Hayton)
12
+
13
+ Notes:
14
+
15
+ * 2010-10-22 @samlown:
16
+ * ActiveModel Attribute support was added but has now been removed due to major performance issues.
17
+ Until these have been resolved (if possible?!) they should not be included. See the
18
+ 'active_model_attrs' if you'd like to test.
19
+
20
+ == CouchRest Model 1.0.0.beta8
21
+
22
+ * Major enhancements
23
+ * Added model generator
4
24
 
5
25
  * Minor enhancements
6
26
  * Raise error on adding objects to "collection_of" without an id
7
27
  * Allow mixing of protected and accessible properties. Any unspecified properties are now assumed to be protected by default
28
+ * Parsing times without zone
29
+ * Using latest rspec (2.0.0.beta.19)
8
30
 
9
31
  == CouchRest Model 1.0.0.beta7
10
32
 
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__),'lib', 'couchrest', 'model')
@@ -2,7 +2,7 @@ module CouchRest
2
2
  module Model
3
3
  module Associations
4
4
 
5
- # Basic support for relationships between ExtendedDocuments
5
+ # Basic support for relationships between CouchRest::Model::Base
6
6
 
7
7
  def self.included(base)
8
8
  base.extend(ClassMethods)
@@ -171,24 +171,32 @@ module CouchRest
171
171
  (array ||= []).compact!
172
172
  casted_by[property.to_s] = [] # replace the original array!
173
173
  array.compact.each do |obj|
174
+ check_obj(obj)
174
175
  casted_by[property.to_s] << obj.id
175
176
  end
176
177
  super(array)
177
178
  end
179
+
178
180
  def << obj
181
+ check_obj(obj)
179
182
  casted_by[property.to_s] << obj.id
180
183
  super(obj)
181
184
  end
185
+
182
186
  def push(obj)
187
+ check_obj(obj)
183
188
  casted_by[property.to_s].push obj.id
184
189
  super(obj)
185
190
  end
191
+
186
192
  def unshift(obj)
193
+ check_obj(obj)
187
194
  casted_by[property.to_s].unshift obj.id
188
195
  super(obj)
189
196
  end
190
197
 
191
198
  def []= index, obj
199
+ check_obj(obj)
192
200
  casted_by[property.to_s][index] = obj.id
193
201
  super(index, obj)
194
202
  end
@@ -197,10 +205,18 @@ module CouchRest
197
205
  casted_by[property.to_s].pop
198
206
  super
199
207
  end
208
+
200
209
  def shift
201
210
  casted_by[property.to_s].shift
202
211
  super
203
212
  end
213
+
214
+ protected
215
+
216
+ def check_obj(obj)
217
+ raise "Object cannot be added to #{casted_by.class.to_s}##{property.to_s} collection unless saved" if obj.new?
218
+ end
219
+
204
220
  end
205
221
 
206
222