Merge branch 'master' into adv_design
This commit is contained in:
commit
a79c2d516a
5 changed files with 27 additions and 6 deletions
|
@ -6,7 +6,6 @@ PATH
|
|||
couchrest (~> 1.0.1)
|
||||
mime-types (~> 1.15)
|
||||
railties (~> 3.0.0)
|
||||
rspec (>= 2.0.0)
|
||||
tzinfo (~> 0.3.22)
|
||||
|
||||
GEM
|
||||
|
|
10
README.md
10
README.md
|
@ -238,9 +238,9 @@ you'd like to model, CouchRest Model supports creating anonymous classes:
|
|||
class Cat < CouchRest::Model::Base
|
||||
property :name, String
|
||||
|
||||
property :toys do |toy|
|
||||
toy.property :name, String
|
||||
toy.property :rating, Integer
|
||||
property :toys do
|
||||
property :name, String
|
||||
property :rating, Integer
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -248,7 +248,9 @@ you'd like to model, CouchRest Model supports creating anonymous classes:
|
|||
@cat.toys.last.rating == 5
|
||||
@cat.toys.last.name == 'catnip ball'
|
||||
|
||||
Anonymous classes will *only* create arrays of objects.
|
||||
Anonymous classes will *only* create arrays of objects. If you're more of the traditional type, a block parameter
|
||||
can be provided allowing you to use this variable before each method call inside the anonymous class. This is useful
|
||||
if you need to access variables outside of the block.
|
||||
|
||||
|
||||
## Assocations
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
== 1.0.1
|
||||
|
||||
* Minor enhancements:
|
||||
* A yield parameter in an anonymous casted model property block is no longer required (@samlown)
|
||||
|
||||
== CouchRest Model 1.0.0
|
||||
|
||||
* Major enhancements
|
||||
|
|
|
@ -156,7 +156,11 @@ module CouchRest
|
|||
type = Class.new(Hash) do
|
||||
include CastedModel
|
||||
end
|
||||
type.class_eval { yield type }
|
||||
if block.arity == 1 # Traditional, with options
|
||||
type.class_eval { yield type }
|
||||
else
|
||||
type.instance_exec(&block)
|
||||
end
|
||||
type = [type] # inject as an array
|
||||
end
|
||||
property = Property.new(name, type, options)
|
||||
|
|
|
@ -24,6 +24,9 @@ class DummyModel < CouchRest::Model::Base
|
|||
property :sub_models do |child|
|
||||
child.property :title
|
||||
end
|
||||
property :param_free_sub_models do
|
||||
property :title
|
||||
end
|
||||
end
|
||||
|
||||
class WithCastedCallBackModel < Hash
|
||||
|
@ -100,6 +103,14 @@ describe CouchRest::Model::CastedModel do
|
|||
@obj.sub_models << {:title => 'test'}
|
||||
@obj.sub_models.first.title.should eql('test')
|
||||
end
|
||||
it "should be empty intitally (without params)" do
|
||||
@obj.param_free_sub_models.should_not be_nil
|
||||
@obj.param_free_sub_models.should be_empty
|
||||
end
|
||||
it "should be updatable using a hash (without params)" do
|
||||
@obj.param_free_sub_models << {:title => 'test'}
|
||||
@obj.param_free_sub_models.first.title.should eql('test')
|
||||
end
|
||||
end
|
||||
|
||||
describe "casted as attribute" do
|
||||
|
|
Loading…
Reference in a new issue