rails_dynamic_associations 0.2.1.real → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2e750c6c7f3dff5b63c11d91a5636cb7aeffc31b
4
- data.tar.gz: c8f63f3d0831bbe148c3ebde7563f36548d078e5
2
+ SHA256:
3
+ metadata.gz: 8b7b48b2770c9ae7b6273ddfa0c792f074424f2e0b90973ea5683c34cdf738b6
4
+ data.tar.gz: 759bb756a6b7d0ad50542bddf4310b1b55d4e6ea1fed072a72fc740b1bc17002
5
5
  SHA512:
6
- metadata.gz: ed9168cf7e38072e7971ecf38a9550d5a0c30ad27cd2a998e943d8cc7c7211243c94bfd7b475a326e0c1466debe3352b8ed0832de66defb86d57a027adcecd22
7
- data.tar.gz: 6fb4f259c4915c9fe4c6edb2223e8ebe8376315c937c31e3f2ffb7a95fcc8afd04ff79382c72efa923d75f5035a71377020c92dc20d642f9efd57bb967b8d135
6
+ metadata.gz: 8f213dcd1c0317e892b4a8f849bdab9be75d9033ecdb401a7147f8ff8cac2862a8a45c1de2732ff841a24e2187e871bf947584679d2b5e4194fe50529bc6a3b0
7
+ data.tar.gz: 69af7d101d87093b6f1a240a9b4b8890b34442c5dd7ca68285d317cdc072c00da77f2fce1297c4267d429f5a92781951061c0073f012832727fc10ce6979db0e
@@ -1,7 +1,7 @@
1
1
  class Relation < ActiveRecord::Base
2
- belongs_to :source, polymorphic: true
3
- belongs_to :target, polymorphic: true
4
- belongs_to :role
2
+ belongs_to :source, polymorphic: true, optional: true
3
+ belongs_to :target, polymorphic: true, optional: true
4
+ belongs_to :role, optional: true
5
5
 
6
6
  delegate :name, to: :role, allow_nil: true
7
7
 
@@ -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").
@@ -31,9 +31,9 @@ class Relation < ActiveRecord::Base
31
31
  when Symbol then
32
32
  send "#{method}_#{object}"
33
33
  when Class then
34
- where "#{association}_type" => object.base_class
34
+ where "#{association}_type" => object.base_class.name
35
35
  else
36
- where "#{association}_type" => object.class.base_class,
36
+ where "#{association}_type" => object.class.base_class.name,
37
37
  "#{association}_id" => object.id
38
38
  end
39
39
  }
@@ -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.2.1.real'
2
+ VERSION = '0.3.1'
3
3
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_dynamic_associations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1.real
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: 2015-07-28 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
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.0'
19
+ version: 5.0.0.beta
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '4.0'
26
+ version: 5.0.0.beta
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rails_model_load_hook
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -93,12 +93,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
93
  version: '0'
94
94
  required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  requirements:
96
- - - ">"
96
+ - - ">="
97
97
  - !ruby/object:Gem::Version
98
- version: 1.3.1
98
+ version: '0'
99
99
  requirements: []
100
- rubyforge_project:
101
- rubygems_version: 2.4.5
100
+ rubygems_version: 3.3.5
102
101
  signing_key:
103
102
  specification_version: 4
104
103
  summary: DB-driven model associations for Rails.