ripple-anaf 0.8.0.beta1 → 0.8.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -41,12 +41,17 @@ And in your views you can use fields_for:
41
41
 
42
42
  <% end %>
43
43
 
44
+ == Installation
45
+
46
+ Currently in pre-release for testing.
47
+
48
+ gem install ripple-anaf --pre
49
+
44
50
  == Supported Features
45
51
 
46
- * Same DSL for linked and embedded documents (except embedded many)
47
- * :reject_if
48
- * :allow_destroy
49
- * :update_only (soon)
52
+ * Same DSL for linked and embedded documents
53
+ * :reject_if
54
+ * :allow_destroy
50
55
 
51
56
  == Note on Patches/Pull Requests
52
57
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.0.beta1
1
+ 0.8.0.beta2
@@ -71,7 +71,31 @@ module Ripple
71
71
  # { :key => 'yyy', :reference => 'updated foo2' } ])
72
72
  # manifest.shipments.first.reference # => updated foo1
73
73
  # manifest.shipments.second.reference # => updated foo2
74
+ #
75
+ # NOTE: On many embedded, then entire collection of embedded documents is replaced, as there
76
+ # is no key to specifically update.
74
77
  #
78
+ # Given
79
+ #
80
+ # class Manifest
81
+ # include Ripple::Documnet
82
+ # many :signatures
83
+ # accepts_nested_attributes_for :signatures
84
+ # end
85
+ #
86
+ # class Signature
87
+ # include Ripple::EmbeddedDocument
88
+ # property :esignature, String
89
+ # end
90
+ #
91
+ # The assigning of attributes replaces existing:
92
+ #
93
+ # manifest = Manifest.create(:signature_attributes => [ { :esig => 'a00001' }, { :esig => 'b00001' } ]
94
+ # manifest.signatures # => [<Signature esig="a00001">, <Signature esig="b00001">]
95
+ #
96
+ # manifest.signature_attributes = [ { :esig => 'c00001' } ]
97
+ # manifest.signatures # => [<Signature esig="c00001">]
98
+ #
75
99
  module ClassMethods
76
100
 
77
101
  def accepts_nested_attributes_for(*attr_names)
@@ -184,7 +208,14 @@ module Ripple
184
208
  end
185
209
 
186
210
  def assign_nested_attributes_for_many_embedded_association(association_name, attributes_collection)
187
- raise NotImplementedError, "Unclear how to identify which embedded document to update without a key"
211
+ options = nested_attributes_options[association_name]
212
+ send(:"#{association_name}=", []) # Clobber existing
213
+ attributes_collection.each do |attributes|
214
+ attributes = attributes.stringify_keys
215
+ if !reject_new_record?(association_name, attributes)
216
+ send(association_name).build(attributes.except(*UNASSIGNABLE_KEYS))
217
+ end
218
+ end
188
219
  end
189
220
 
190
221
  def assign_nested_attributes_for_many_linked_association(association_name, attributes_collection)
data/ripple-anaf.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ripple-anaf}
8
- s.version = "0.8.0.beta1"
8
+ s.version = "0.8.0.beta2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Brian Kaney"]
12
- s.date = %q{2010-09-05}
12
+ s.date = %q{2010-09-25}
13
13
  s.description = %q{Adds the DSL for ANAF for Ripple, an ORM for Riak}
14
14
  s.email = %q{brian@vermonster.com}
15
15
  s.extra_rdoc_files = [
@@ -142,7 +142,7 @@ describe Ripple::NestedAttributes do
142
142
  end
143
143
  end
144
144
 
145
- context ":one engine (embedded)" do
145
+ context "one :engine (embedded)" do
146
146
  subject { Car.new }
147
147
 
148
148
  it { should respond_to(:engine_attributes=) }
@@ -196,6 +196,41 @@ describe Ripple::NestedAttributes do
196
196
  end
197
197
  end
198
198
 
199
+ context "many :seats (embedded)" do
200
+ subject { Car.new }
201
+
202
+ it { should respond_to(:seats_attributes=) }
203
+
204
+ it "should not have passengers" do
205
+ subject.seats.should == []
206
+ end
207
+
208
+ describe "creation" do
209
+ subject { Car.new(:make => 'VW',
210
+ :model => 'Rabbit',
211
+ :seats_attributes => [ { :color => 'red' },
212
+ { :color => 'blue' },
213
+ { :color => 'brown' } ] ) }
214
+
215
+ it "should have 3 seats" do
216
+ subject.seats.size.should == 3
217
+ end
218
+
219
+ it "should have 3 passengers with specified names" do
220
+ subject.seats.first.color.should == 'red'
221
+ subject.seats.second.color.should == 'blue'
222
+ subject.seats.third.color.should == 'brown'
223
+ end
224
+
225
+ specify "replace/clobber" do
226
+ subject.seats_attributes = [ { :color => 'orange' } ]
227
+ subject.seats.size.should == 1
228
+ subject.seats.first.color.should == 'orange'
229
+ end
230
+
231
+ end
232
+ end
233
+
199
234
  context ":reject_if" do
200
235
  it "should not create a wheel" do
201
236
  car = Car.new(:wheels_attributes => [ { :diameter => 10 } ])
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 0
7
7
  - 8
8
8
  - 0
9
- - beta1
10
- version: 0.8.0.beta1
9
+ - beta2
10
+ version: 0.8.0.beta2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brian Kaney
@@ -15,11 +15,12 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-05 00:00:00 -04:00
18
+ date: 2010-09-25 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: rspec
23
+ prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
24
25
  none: false
25
26
  requirements:
@@ -33,10 +34,10 @@ dependencies:
33
34
  - 19
34
35
  version: 2.0.0.beta.19
35
36
  type: :development
36
- prerelease: false
37
37
  version_requirements: *id001
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: bundler
40
+ prerelease: false
40
41
  requirement: &id002 !ruby/object:Gem::Requirement
41
42
  none: false
42
43
  requirements:
@@ -48,10 +49,10 @@ dependencies:
48
49
  - 0
49
50
  version: 1.0.0
50
51
  type: :development
51
- prerelease: false
52
52
  version_requirements: *id002
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: ripple
55
+ prerelease: false
55
56
  requirement: &id003 !ruby/object:Gem::Requirement
56
57
  none: false
57
58
  requirements:
@@ -63,7 +64,6 @@ dependencies:
63
64
  - 0
64
65
  version: 0.8.0
65
66
  type: :runtime
66
- prerelease: false
67
67
  version_requirements: *id003
68
68
  description: Adds the DSL for ANAF for Ripple, an ORM for Riak
69
69
  email: brian@vermonster.com
@@ -112,7 +112,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
112
  requirements:
113
113
  - - ">="
114
114
  - !ruby/object:Gem::Version
115
- hash: 2319011372961580373
116
115
  segments:
117
116
  - 0
118
117
  version: "0"