Merge branch 'master' into adv_design
This commit is contained in:
commit
a79c2d516a
|
@ -6,7 +6,6 @@ PATH
|
||||||
couchrest (~> 1.0.1)
|
couchrest (~> 1.0.1)
|
||||||
mime-types (~> 1.15)
|
mime-types (~> 1.15)
|
||||||
railties (~> 3.0.0)
|
railties (~> 3.0.0)
|
||||||
rspec (>= 2.0.0)
|
|
||||||
tzinfo (~> 0.3.22)
|
tzinfo (~> 0.3.22)
|
||||||
|
|
||||||
GEM
|
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
|
class Cat < CouchRest::Model::Base
|
||||||
property :name, String
|
property :name, String
|
||||||
|
|
||||||
property :toys do |toy|
|
property :toys do
|
||||||
toy.property :name, String
|
property :name, String
|
||||||
toy.property :rating, Integer
|
property :rating, Integer
|
||||||
end
|
end
|
||||||
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.rating == 5
|
||||||
@cat.toys.last.name == 'catnip ball'
|
@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
|
## 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
|
== CouchRest Model 1.0.0
|
||||||
|
|
||||||
* Major enhancements
|
* Major enhancements
|
||||||
|
|
|
@ -156,7 +156,11 @@ module CouchRest
|
||||||
type = Class.new(Hash) do
|
type = Class.new(Hash) do
|
||||||
include CastedModel
|
include CastedModel
|
||||||
end
|
end
|
||||||
|
if block.arity == 1 # Traditional, with options
|
||||||
type.class_eval { yield type }
|
type.class_eval { yield type }
|
||||||
|
else
|
||||||
|
type.instance_exec(&block)
|
||||||
|
end
|
||||||
type = [type] # inject as an array
|
type = [type] # inject as an array
|
||||||
end
|
end
|
||||||
property = Property.new(name, type, options)
|
property = Property.new(name, type, options)
|
||||||
|
|
|
@ -24,6 +24,9 @@ class DummyModel < CouchRest::Model::Base
|
||||||
property :sub_models do |child|
|
property :sub_models do |child|
|
||||||
child.property :title
|
child.property :title
|
||||||
end
|
end
|
||||||
|
property :param_free_sub_models do
|
||||||
|
property :title
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class WithCastedCallBackModel < Hash
|
class WithCastedCallBackModel < Hash
|
||||||
|
@ -100,6 +103,14 @@ describe CouchRest::Model::CastedModel do
|
||||||
@obj.sub_models << {:title => 'test'}
|
@obj.sub_models << {:title => 'test'}
|
||||||
@obj.sub_models.first.title.should eql('test')
|
@obj.sub_models.first.title.should eql('test')
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe "casted as attribute" do
|
describe "casted as attribute" do
|
||||||
|
|
Loading…
Reference in a new issue