acts-as-joinable 0.1.6.3 → 0.1.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/lib/acts_as_joinable/core.rb +20 -7
- data/test/test_acts_as_joinable.rb +1 -2
- metadata +3 -3
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ require 'rake/gempackagetask'
|
|
5
5
|
spec = Gem::Specification.new do |s|
|
6
6
|
s.name = "acts-as-joinable"
|
7
7
|
s.authors = ["Lance Pollard"]
|
8
|
-
s.version = "0.1.6.
|
8
|
+
s.version = "0.1.6.5"
|
9
9
|
s.summary = "ActsAsJoinable: DRYing up Many-to-Many Relationships in ActiveRecord"
|
10
10
|
s.homepage = "http://github.com/viatropos/acts-as-joinable"
|
11
11
|
s.email = "lancejpollard@gmail.com"
|
@@ -87,10 +87,11 @@ module ActsAsJoinable
|
|
87
87
|
wanted_classes.pop
|
88
88
|
|
89
89
|
joins.each do |type|
|
90
|
-
singular_type = type.to_s.singularize
|
91
90
|
if association_type == :has_one
|
91
|
+
singular_type = type.to_s.to_sym
|
92
92
|
plural_type = type.to_s.pluralize.to_sym
|
93
93
|
else
|
94
|
+
singular_type = type.to_s.singularize.to_sym
|
94
95
|
plural_type = type.to_s.to_sym
|
95
96
|
end
|
96
97
|
class_name = opts[:class_name] || type.to_s.classify
|
@@ -146,15 +147,28 @@ module ActsAsJoinable
|
|
146
147
|
through_options[:uniq] = true
|
147
148
|
end
|
148
149
|
|
150
|
+
|
149
151
|
unless has_association?(through_relationship)
|
150
152
|
has_many through_relationship, through_options
|
151
153
|
end
|
152
|
-
|
153
|
-
add_association(relationship.to_s, plural_type, options, join_context, join_value,
|
154
|
+
|
155
|
+
add_association(relationship.to_s, plural_type, options, join_context, join_value, &block)
|
154
156
|
|
155
157
|
if association_type == :has_one
|
156
|
-
add_has_one(singular_type, plural_type, through_relationship, class_name)
|
158
|
+
add_has_one(singular_type, plural_type, through_relationship, class_name, join_context, join_value, options)
|
159
|
+
end
|
160
|
+
|
161
|
+
if nestable
|
162
|
+
accepts_nested_attributes_for plural_type.to_sym
|
163
|
+
if association_type == :has_one
|
164
|
+
define_method "#{singular_type}_attributes=" do |params|
|
165
|
+
params = params.first if params.is_a?(Array)
|
166
|
+
|
167
|
+
self.send("#{plural_type}_attributes=", [params])
|
168
|
+
end
|
169
|
+
end
|
157
170
|
end
|
171
|
+
|
158
172
|
end
|
159
173
|
end
|
160
174
|
end
|
@@ -173,7 +187,7 @@ module ActsAsJoinable
|
|
173
187
|
self.reflect_on_all_associations.map(&:name).include?(name.to_sym)
|
174
188
|
end
|
175
189
|
|
176
|
-
def add_has_one(singular_type, plural_type, relationship_with_context, class_name)
|
190
|
+
def add_has_one(singular_type, plural_type, relationship_with_context, class_name, join_context, join_value, options)
|
177
191
|
define_method singular_type do
|
178
192
|
send(plural_type).last
|
179
193
|
end
|
@@ -198,7 +212,7 @@ module ActsAsJoinable
|
|
198
212
|
end
|
199
213
|
end
|
200
214
|
|
201
|
-
def add_association(relationship, plural_type, options, join_context, join_value,
|
215
|
+
def add_association(relationship, plural_type, options, join_context, join_value, &block)
|
202
216
|
eval_options = {}
|
203
217
|
eval_options[:context] = join_context unless join_context.to_s == options[:class_name].to_s.underscore.singularize
|
204
218
|
|
@@ -223,7 +237,6 @@ module ActsAsJoinable
|
|
223
237
|
end
|
224
238
|
EOF
|
225
239
|
end
|
226
|
-
accepts_nested_attributes_for plural_type.to_sym if nestable
|
227
240
|
end
|
228
241
|
end
|
229
242
|
|
@@ -61,9 +61,8 @@ class ActsAsJoinableTest < ActiveRecord::TestCase
|
|
61
61
|
|
62
62
|
parent = SubGroup.create!(
|
63
63
|
:title => "subgroup with has_one :cover_image",
|
64
|
-
:
|
64
|
+
:cover_image_attributes => {:title => "an image"}
|
65
65
|
)
|
66
|
-
|
67
66
|
assert_equal 1, Asset.count
|
68
67
|
end
|
69
68
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts-as-joinable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 85
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
9
|
- 6
|
10
|
-
-
|
11
|
-
version: 0.1.6.
|
10
|
+
- 5
|
11
|
+
version: 0.1.6.5
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Lance Pollard
|