rails_dynamic_associations 0.3.0 → 0.3.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
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8b7b48b2770c9ae7b6273ddfa0c792f074424f2e0b90973ea5683c34cdf738b6
|
4
|
+
data.tar.gz: 759bb756a6b7d0ad50542bddf4310b1b55d4e6ea1fed072a72fc740b1bc17002
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f213dcd1c0317e892b4a8f849bdab9be75d9033ecdb401a7147f8ff8cac2862a8a45c1de2732ff841a24e2187e871bf947584679d2b5e4194fe50529bc6a3b0
|
7
|
+
data.tar.gz: 69af7d101d87093b6f1a240a9b4b8890b34442c5dd7ca68285d317cdc072c00da77f2fce1297c4267d429f5a92781951061c0073f012832727fc10ce6979db0e
|
data/app/models/relation.rb
CHANGED
@@ -9,7 +9,7 @@ class Relation < ActiveRecord::Base
|
|
9
9
|
references(:roles).includes :role
|
10
10
|
}
|
11
11
|
|
12
|
-
association_directions.shortcuts.each &-> (association, method) do
|
12
|
+
association_directions.shortcuts.each &-> ((association, method)) do
|
13
13
|
scope "#{method}_abstract", -> (object = nil) {
|
14
14
|
if object then
|
15
15
|
send("#{method}_abstract").
|
@@ -13,24 +13,27 @@ module RailsDynamicAssociations::ActiveRecord
|
|
13
13
|
define_association type, target
|
14
14
|
define_association type, target, role if role
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
association_directions.recursive
|
17
|
+
.select { |association, method| reflect_on_association association }
|
18
|
+
.reject { |association, method| method_defined? method }
|
19
|
+
.each { |association, method| define_recursive_methods association, method }
|
19
20
|
end
|
20
21
|
|
21
22
|
private
|
22
23
|
|
23
24
|
def define_relations_association type, target = self, role = nil
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
relations_association_name(type, target, role).tap do |association|
|
26
|
+
next if reflect_on_association association
|
27
|
+
|
28
|
+
has_many association, role && -> { where role_id: role.id },
|
29
|
+
as: association_directions.opposite(type), class_name: 'Relation'
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
32
33
|
def define_association type, target = self, role = nil
|
33
|
-
|
34
|
+
association_name(type, target, role).tap do |association|
|
35
|
+
next if reflect_on_association association
|
36
|
+
|
34
37
|
has_many association,
|
35
38
|
through: define_relations_association(type, target, role),
|
36
39
|
source: type,
|
@@ -77,6 +80,10 @@ module RailsDynamicAssociations::ActiveRecord
|
|
77
80
|
end
|
78
81
|
end
|
79
82
|
|
83
|
+
def relations_association_name type, target = self, role = nil
|
84
|
+
:"#{role ? association_name(type, target, role).to_s.singularize : type}_relations"
|
85
|
+
end
|
86
|
+
|
80
87
|
def association_name type, target = self, role = nil
|
81
88
|
if role then
|
82
89
|
association_name_with_role type, target, role
|
@@ -10,7 +10,7 @@ module RailsDynamicAssociations::ActiveRecord
|
|
10
10
|
end
|
11
11
|
|
12
12
|
module ClassMethods
|
13
|
-
RailsDynamicAssociations::Config.association_directions.opposite_shortcuts.each &-> (association, method) do
|
13
|
+
RailsDynamicAssociations::Config.association_directions.opposite_shortcuts.each &-> ((association, method)) do
|
14
14
|
define_method "#{association}_relations" do
|
15
15
|
Relation.send method, self
|
16
16
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_dynamic_associations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Senko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -97,8 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
97
|
- !ruby/object:Gem::Version
|
98
98
|
version: '0'
|
99
99
|
requirements: []
|
100
|
-
|
101
|
-
rubygems_version: 2.5.1
|
100
|
+
rubygems_version: 3.3.5
|
102
101
|
signing_key:
|
103
102
|
specification_version: 4
|
104
103
|
summary: DB-driven model associations for Rails.
|