embedded_associations 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/embedded_associations/version.rb +1 -1
- data/lib/embedded_associations.rb +10 -8
- data/spec/spec_helper.rb +0 -2
- metadata +2 -2
@@ -30,6 +30,10 @@ module EmbeddedAssociations
|
|
30
30
|
resource_name
|
31
31
|
end
|
32
32
|
|
33
|
+
def filter_attributes(name, attrs, action)
|
34
|
+
attrs
|
35
|
+
end
|
36
|
+
|
33
37
|
# Simple callbacks for now, eventually should use a filter system
|
34
38
|
def before_embedded(record, action); end
|
35
39
|
|
@@ -100,10 +104,6 @@ module EmbeddedAssociations
|
|
100
104
|
end
|
101
105
|
end
|
102
106
|
|
103
|
-
def filter_attributes(name, attrs, action)
|
104
|
-
attrs
|
105
|
-
end
|
106
|
-
|
107
107
|
def handle_plural_resource(parent, name, attr_array, child_definition)
|
108
108
|
current_assoc = parent.send(name)
|
109
109
|
|
@@ -115,16 +115,17 @@ module EmbeddedAssociations
|
|
115
115
|
end
|
116
116
|
|
117
117
|
attr_array.each do |attrs|
|
118
|
+
attrs = ActionController::Parameters.new(attrs)
|
118
119
|
if id = attrs['id']
|
119
120
|
# can't use current_assoc.find(id), see http://stackoverflow.com/questions/11605120/autosave-ignored-on-has-many-relation-what-am-i-missing
|
120
121
|
r = current_assoc.find{|r| r.id == id.to_i}
|
121
|
-
attrs = filter_attributes
|
122
|
+
attrs = controller.send(:filter_attributes, r.class.name, attrs, :update)
|
122
123
|
handle_resource(child_definition, r, attrs) if child_definition
|
123
124
|
r.assign_attributes(attrs)
|
124
125
|
run_before_update_callbacks(r)
|
125
126
|
else
|
126
127
|
r = current_assoc.build()
|
127
|
-
attrs = filter_attributes
|
128
|
+
attrs = controller.send(:filter_attributes, r.class.name, attrs, :create)
|
128
129
|
handle_resource(child_definition, r, attrs) if child_definition
|
129
130
|
r.assign_attributes(attrs)
|
130
131
|
run_before_create_callbacks(r)
|
@@ -134,10 +135,11 @@ module EmbeddedAssociations
|
|
134
135
|
|
135
136
|
def handle_singular_resource(parent, name, attrs, child_definition)
|
136
137
|
current_assoc = parent.send(name)
|
138
|
+
attrs = ActionController::Parameters.new(attrs)
|
137
139
|
|
138
140
|
if r = current_assoc
|
139
141
|
if attrs
|
140
|
-
attrs = filter_attributes
|
142
|
+
attrs = controller.send(:filter_attributes, r.class.name, attrs, :update)
|
141
143
|
handle_resource(child_definition, r, attrs) if child_definition
|
142
144
|
r.assign_attributes(attrs)
|
143
145
|
run_before_update_callbacks(r)
|
@@ -148,7 +150,7 @@ module EmbeddedAssociations
|
|
148
150
|
end
|
149
151
|
elsif attrs
|
150
152
|
r = parent.send("build_#{name}")
|
151
|
-
attrs = filter_attributes
|
153
|
+
attrs = controller.send(:filter_attributes, r.class.name, attrs, :create)
|
152
154
|
handle_resource(child_definition, r, attrs) if child_definition
|
153
155
|
r.assign_attributes(attrs)
|
154
156
|
run_before_create_callbacks(r)
|
data/spec/spec_helper.rb
CHANGED
@@ -13,8 +13,6 @@ require 'rspec/rails'
|
|
13
13
|
|
14
14
|
require 'support/serialization_helpers'
|
15
15
|
|
16
|
-
puts File.expand_path("../support/app/db/migrate/", __FILE__)
|
17
|
-
|
18
16
|
ActiveRecord::Migrator.migrate(File.expand_path("../support/app/db/migrate/", __FILE__))
|
19
17
|
|
20
18
|
RSpec.configure do |config|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embedded_associations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|