eac_rails_utils 0.13.3 → 0.13.4

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
  SHA256:
3
- metadata.gz: 7156f5e6b807386aff176fcb1dbe8461f95de94e60292d19d04112e988e440d8
4
- data.tar.gz: a5a4b862946e67c883889627de183ab18981fa940a87be7918bfe8216990e1dc
3
+ metadata.gz: 843754871487598961a71d16871da8c3556d9d0097f0869838311d56c4e82df8
4
+ data.tar.gz: e5a72c9640c9c6aba5f720bbb1204371c0f63ffdf5309f497e537b0a74406721
5
5
  SHA512:
6
- metadata.gz: aaa6c8a6736f484fc769f892a421b152f2f7eee58d04aca66202cc68ed50aa43823893d22a34627b6361667faa80973f1c7f0aa50bc57a891daf9f0181c3816b
7
- data.tar.gz: aac2e1e91726bdee9526d222c9c0db0955a16071bb014ec5a65803c7bda4af684669c264d2ce486c669626a803e1f6da688b076b5b401e544faac653456bba8d
6
+ metadata.gz: eb890220eb07ca6a06e54a31d877779c043070b502d1a724236e5ea82c07839508487fe6effa5197d48928d1103eff5fd56d81dd8d54a3138a7c5404bf52057d
7
+ data.tar.gz: 94d56786e02f5fd2c3d3d4a7b42cb36ea9d601bf1e89828a1670477f36ce7d36e8d164b3028c709bbdca8f7123aa8971cadd2d03861179e7b0cdde4cc70fe679
@@ -1,38 +1,34 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_model/associations/hooks'
4
3
  require 'activemodel/associations'
5
-
6
- module EacRailsUtils
7
- module Patches
8
- module ActiveModelAssociations
9
- module ScopeExtensionPatch
10
- def add_constraints(scope, owner, association_klass, *extra_args)
11
- if extra_args.any?
12
- refl = extra_args.first
13
- if refl.options[:active_model]
14
- target_ids = refl.options[:target_ids]
15
- return scope.where(id: owner[target_ids])
16
- end
17
- end
18
-
19
- super
20
- end
21
- end
22
- end
23
- end
24
- end
4
+ require 'eac_rails_utils/patches/rails_4'
5
+ require 'eac_rails_utils/patches/rails_5_2'
25
6
 
26
7
  module ActiveModel
27
8
  module Associations
28
9
  module Hooks
29
- def self.init
30
- return unless ::Rails.version < '5'
10
+ class << self
11
+ def init
12
+ init_rails_4 if ::EacRailsUtils::Patches::Rails4.enabled?
13
+ init_rails_5_2 if ::EacRailsUtils::Patches::Rails52.enabled?
14
+ end
15
+
16
+ def init_rails_4
17
+ ActiveSupport.on_load(:active_record) do
18
+ ActiveRecord::Associations::AssociationScope.prepend(
19
+ ::EacRailsUtils::Patches::Rails4.ActiveRecordAssociationsAssociationScope
20
+ )
21
+ end
22
+ end
31
23
 
32
- ActiveSupport.on_load(:active_record) do
33
- ActiveRecord::Associations::AssociationScope.prepend(
34
- ::EacRailsUtils::Patches::ActiveModelAssociations::ScopeExtensionPatch
35
- )
24
+ def init_rails_5_2
25
+ rails_5_2_fix_activemodel_associations_methods
26
+ end
27
+
28
+ def rails_5_2_fix_activemodel_associations_methods
29
+ %i[belongs_to has_many].each do |method|
30
+ ::EacRailsUtils::Patches::Rails52::ActiveModelAssociationMethodFix.new(method)
31
+ end
36
32
  end
37
33
  end
38
34
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'activemodel/associations'
4
+
5
+ module EacRailsUtils
6
+ module Patches
7
+ module Rails4
8
+ module ActiveRecordAssociationsAssociationScope
9
+ def add_constraints(scope, owner, association_klass, *extra_args)
10
+ if extra_args.any?
11
+ refl = extra_args.first
12
+ if refl.options[:active_model]
13
+ target_ids = refl.options[:target_ids]
14
+ return scope.where(id: owner[target_ids])
15
+ end
16
+ end
17
+
18
+ super
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_model/associations/hooks'
4
+ require 'eac_ruby_utils/require_sub'
5
+
6
+ module EacRailsUtils
7
+ module Patches
8
+ module Rails4
9
+ ::EacRubyUtils.require_sub __FILE__
10
+
11
+ class << self
12
+ def enabled?
13
+ ::Rails.version < '5'
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'activemodel/associations'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module EacRailsUtils
7
+ module Patches
8
+ module Rails52
9
+ class ActiveModelAssociationMethodFix
10
+ common_constructor :method_name do
11
+ perform
12
+ end
13
+
14
+ def original_method_new_name
15
+ "original_#{method_name}".to_sym
16
+ end
17
+
18
+ private
19
+
20
+ def the_module
21
+ ::ActiveModel::Associations::ClassMethods
22
+ end
23
+
24
+ def perform
25
+ patch = self
26
+ the_module.class_eval do
27
+ alias_method patch.original_method_new_name, patch.method_name
28
+ remove_method patch.method_name
29
+
30
+ define_method patch.method_name do |name, scope = nil, **options, &extension|
31
+ send(patch.original_method_new_name, name, scope, options, &extension)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_model/associations/hooks'
4
+ require 'eac_ruby_utils/require_sub'
5
+
6
+ module EacRailsUtils
7
+ module Patches
8
+ module Rails52
9
+ ::EacRubyUtils.require_sub __FILE__
10
+
11
+ class << self
12
+ def enabled?
13
+ ::Rails.version >= '5.2'
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRailsUtils
4
- VERSION = '0.13.3'
4
+ VERSION = '0.13.4'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_rails_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.3
4
+ version: 0.13.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - E.A.C.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-22 00:00:00.000000000 Z
11
+ date: 2021-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel-associations
@@ -120,14 +120,14 @@ dependencies:
120
120
  requirements:
121
121
  - - "~>"
122
122
  - !ruby/object:Gem::Version
123
- version: '0.3'
123
+ version: '0.4'
124
124
  type: :development
125
125
  prerelease: false
126
126
  version_requirements: !ruby/object:Gem::Requirement
127
127
  requirements:
128
128
  - - "~>"
129
129
  - !ruby/object:Gem::Version
130
- version: '0.3'
130
+ version: '0.4'
131
131
  description:
132
132
  email:
133
133
  executables: []
@@ -195,6 +195,10 @@ files:
195
195
  - lib/eac_rails_utils/patches.rb
196
196
  - lib/eac_rails_utils/patches/action_controller_base.rb
197
197
  - lib/eac_rails_utils/patches/active_model_associations.rb
198
+ - lib/eac_rails_utils/patches/rails_4.rb
199
+ - lib/eac_rails_utils/patches/rails_4/active_record_associations_association_scope.rb
200
+ - lib/eac_rails_utils/patches/rails_5_2.rb
201
+ - lib/eac_rails_utils/patches/rails_5_2/active_model_association_method_fix.rb
198
202
  - lib/eac_rails_utils/version.rb
199
203
  homepage:
200
204
  licenses: []