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
- SHA1:
3
- metadata.gz: 5f47dcb824c67ac26af7a708bb2e9b09245ae0c9
4
- data.tar.gz: 0331171dd8bd2411b9725d0c65cd928719929d4f
2
+ SHA256:
3
+ metadata.gz: 8b7b48b2770c9ae7b6273ddfa0c792f074424f2e0b90973ea5683c34cdf738b6
4
+ data.tar.gz: 759bb756a6b7d0ad50542bddf4310b1b55d4e6ea1fed072a72fc740b1bc17002
5
5
  SHA512:
6
- metadata.gz: 5f859193b24729bb546465ae5a94555047e481a2f75ee89017898cc2f80947d601c61126b61f8f429a291c396fafa79733c583efb6a92e95562288be77c45b8b
7
- data.tar.gz: 3bfd71ad52e675ec4039f4312996770028bc6ca6bcabfe21908db6d2f27c6086db0044418021ef4834561c2c57de82297ac3c0a3ca2282d376558d96eb09a884
6
+ metadata.gz: 8f213dcd1c0317e892b4a8f849bdab9be75d9033ecdb401a7147f8ff8cac2862a8a45c1de2732ff841a24e2187e871bf947584679d2b5e4194fe50529bc6a3b0
7
+ data.tar.gz: 69af7d101d87093b6f1a240a9b4b8890b34442c5dd7ca68285d317cdc072c00da77f2fce1297c4267d429f5a92781951061c0073f012832727fc10ce6979db0e
@@ -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
- for association, method in association_directions.recursive do
17
- define_recursive_methods association, method if association.in? reflections and not method_defined? method
18
- end
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
- :"#{role ? association_name(type, target, role).to_s.singularize : type}_relations".tap do |association|
25
- unless association.in? reflections then
26
- has_many association, role && -> { where role_id: role.id },
27
- as: association_directions.opposite(type), class_name: 'Relation'
28
- end
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
- unless (association = association_name(type, target, role)).in? reflections then
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
@@ -1,3 +1,3 @@
1
1
  module RailsDynamicAssociations
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  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.0
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: 2016-01-17 00:00:00.000000000 Z
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
- rubyforge_project:
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.