rails_dynamic_associations 0.1.0 → 0.1.1
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4dccbe5a752726f57eb97a9f03323efb4907fe0e
|
4
|
+
data.tar.gz: bba3e032f0bdc486b0bed4290b16a79b2ca14a5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68b1fb01b76e4b128978fcd829089c6a683332fc8b8aa6b1617db4e9bc32732d6636ac8d3e29f4460919f44f91bcb89086df736e179fe9428f00ff42be5ff3e5
|
7
|
+
data.tar.gz: 0c4802a3cf276dac52c6d91d394741830bf8925b800207d94feb1905e2ba40f2a41a12221a4427d5c86b20ef5c871a141f3ad9bb853844f729d954c8caa63812
|
data/app/models/relation.rb
CHANGED
@@ -5,32 +5,32 @@ class Relation < ActiveRecord::Base
|
|
5
5
|
|
6
6
|
delegate :name, to: :role, allow_nil: true
|
7
7
|
|
8
|
-
RailsDynamicAssociations.directions.each &-> (
|
9
|
-
scope "#{
|
8
|
+
RailsDynamicAssociations.directions.each &-> (association, method) do
|
9
|
+
scope "#{method}_abstract", -> (object = nil) {
|
10
10
|
if object then
|
11
|
-
send
|
11
|
+
send method, object
|
12
12
|
else
|
13
13
|
all
|
14
14
|
end.
|
15
|
-
where "#{
|
15
|
+
where "#{association}_id" => nil
|
16
16
|
}
|
17
17
|
|
18
|
-
scope "#{
|
19
|
-
send("#{
|
20
|
-
where "#{
|
18
|
+
scope "#{method}_general", -> {
|
19
|
+
send("#{method}_abstract").
|
20
|
+
where "#{association}_type" => nil
|
21
21
|
}
|
22
22
|
|
23
|
-
scope
|
23
|
+
scope method, -> (object) {
|
24
24
|
case object
|
25
25
|
when nil then
|
26
26
|
all
|
27
27
|
when Symbol then
|
28
|
-
send "#{
|
28
|
+
send "#{method}_#{object}"
|
29
29
|
when Class then
|
30
|
-
where "#{
|
30
|
+
where "#{association}_type" => object.base_class
|
31
31
|
else
|
32
|
-
where "#{
|
33
|
-
"#{
|
32
|
+
where "#{association}_type" => object.class.base_class,
|
33
|
+
"#{association}_id" => object.id
|
34
34
|
end
|
35
35
|
}
|
36
36
|
end
|
data/app/models/role.rb
CHANGED
@@ -13,11 +13,11 @@ class Role < ActiveRecord::Base
|
|
13
13
|
}
|
14
14
|
|
15
15
|
scope :in, -> (object) {
|
16
|
-
where relations: { id: object
|
16
|
+
where relations: { id: Relation.to(object) } # TODO: simplify
|
17
17
|
}
|
18
18
|
|
19
19
|
scope :for, -> (subject) {
|
20
|
-
where relations: { id: subject
|
20
|
+
where relations: { id: Relation.of(subject) } # TODO: simplify
|
21
21
|
}
|
22
22
|
|
23
23
|
def self.find_or_create_named *names
|
@@ -90,7 +90,7 @@ module RailsDynamicAssociations::ActiveRecord
|
|
90
90
|
end
|
91
91
|
else
|
92
92
|
if target == self then
|
93
|
-
RailsDynamicAssociations.
|
93
|
+
RailsDynamicAssociations.self_referential[type].to_s
|
94
94
|
else
|
95
95
|
target.name.split('::').reverse.join
|
96
96
|
end
|