acts-as-joinable 0.1.6.8 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +3 -1
- data/Rakefile +1 -1
- data/lib/acts_as_joinable/core.rb +6 -5
- metadata +4 -5
data/README.markdown
CHANGED
@@ -98,4 +98,6 @@ You can always add columns to the relationship table, but the foundation is set.
|
|
98
98
|
|
99
99
|
<cite>copyright @viatropos 2010</cite>
|
100
100
|
|
101
|
-
http://rors.org/2008/10/26/dont-escape-in-strings
|
101
|
+
http://rors.org/2008/10/26/dont-escape-in-strings
|
102
|
+
|
103
|
+
- Handle case where one side has_one and the other has_many
|
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.
|
8
|
+
s.version = "0.1.7"
|
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"
|
@@ -61,6 +61,7 @@ module ActsAsJoinable
|
|
61
61
|
# class name of the model we're joining to self
|
62
62
|
# otherwise it's retrieved from joins.each...
|
63
63
|
class_name = opts[:class_name] || nil
|
64
|
+
sti = (opts[:subclasses] || []).map { |i| i.to_s.camelize.constantize }
|
64
65
|
# contexts defining the relationship between self and target
|
65
66
|
contexts = [opts[:context] || []].flatten
|
66
67
|
context = contexts.first
|
@@ -79,7 +80,7 @@ module ActsAsJoinable
|
|
79
80
|
|
80
81
|
after_destroy :destroy_relationships unless after_destroy.map(&:method).include?(:destroy_relationships)
|
81
82
|
|
82
|
-
related_classes = (ancestors.reverse - included_modules + send(:subclasses)).uniq
|
83
|
+
related_classes = (ancestors.reverse - included_modules + send(:subclasses) + sti).uniq
|
83
84
|
wanted_classes = []
|
84
85
|
while wanted_classes.push(related_classes.pop)
|
85
86
|
break if wanted_classes.last == base_class.superclass
|
@@ -265,7 +266,7 @@ module ActsAsJoinable
|
|
265
266
|
send(plural_type) << value
|
266
267
|
end
|
267
268
|
send(plural_type).each do |object|
|
268
|
-
send(plural_type).delete(object) unless object.id == value.id
|
269
|
+
send(plural_type).delete(object) unless (value && object.id == value.id)
|
269
270
|
end
|
270
271
|
end
|
271
272
|
define_method "#{singular_type}_id" do
|
@@ -319,17 +320,17 @@ module ActsAsJoinable
|
|
319
320
|
return false if conditions[:context] && !Array(conditions[:context]).include?(relationship.context)
|
320
321
|
true
|
321
322
|
end
|
322
|
-
|
323
|
+
|
323
324
|
def parent_relationships_for(conditions = {})
|
324
325
|
parent_relationships.select do |relationship|
|
325
326
|
relationship_matches?(relationship, conditions)
|
326
|
-
end
|
327
|
+
end.uniq_by(&:parent_id)
|
327
328
|
end
|
328
329
|
|
329
330
|
def child_relationships_for(conditions = {})
|
330
331
|
child_relationships.select do |relationship|
|
331
332
|
relationship_matches?(relationship, conditions)
|
332
|
-
end
|
333
|
+
end.uniq_by(&:child_id)
|
333
334
|
end
|
334
335
|
end
|
335
336
|
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts-as-joinable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
|
11
|
-
version: 0.1.6.8
|
9
|
+
- 7
|
10
|
+
version: 0.1.7
|
12
11
|
platform: ruby
|
13
12
|
authors:
|
14
13
|
- Lance Pollard
|
@@ -16,7 +15,7 @@ autorequire:
|
|
16
15
|
bindir: bin
|
17
16
|
cert_chain: []
|
18
17
|
|
19
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-06 00:00:00 -05:00
|
20
19
|
default_executable:
|
21
20
|
dependencies: []
|
22
21
|
|