eac_rails_utils 0.11.1 → 0.11.2

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
2
  SHA256:
3
- metadata.gz: 68b43bfb10790f9960831364c2ba228b22131e3f1fa24f84d7074ba784ff580d
4
- data.tar.gz: 6bb8f25d260a942086d89c4f33ace3888ec99605d38b72c6ba023529b759bfd5
3
+ metadata.gz: bb6393471b8d317c18c157556614ea1f40444ca56b5950998a8c51157f0101d8
4
+ data.tar.gz: b9531813f5e6283a377e0044c1b1ad1d72336701d2e2a280fa3a0ebef6ce5102
5
5
  SHA512:
6
- metadata.gz: e51d8cb33ff34bf9698bb99f767d7e6adb69b2b2255a5cd787f5e1febd009bd25df5f0399e3a5e4dd031820580ca8a2942edacfd68a980c88ca94019ed9851de
7
- data.tar.gz: 6353e5e12d10396ed143717e2b18c6844ffc192215e28dd3fc1da498ee7af6b18593097dec712a714d09914e23ffe4d5375a3db2c47df3984e4ef5ee0d50c731
6
+ metadata.gz: c111435248f4358873989293cc8b49826f15c01bcd78186411bb39a582c0364626ac1ec8b2ed1d4d7d2ba81b315da4eda805c13582a562a9a9881d4173ad19f4
7
+ data.tar.gz: add93d610c6303fe8687f193854af9527b48c2e31ff705bb849ccc346670055d1640d3dae4293637ac06733af73dcc1cbb7f15f7dffe9ad6562019761a4d42e8
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'activemodel/associations'
3
+ require 'eac_rails_utils/patches/active_model_associations'
4
4
  require 'virtus'
5
5
 
6
6
  module EacRailsUtils
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_model/associations/hooks'
4
+ 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
25
+
26
+ module ActiveModel
27
+ module Associations
28
+ module Hooks
29
+ def self.init
30
+ ActiveSupport.on_load(:active_record) do
31
+ ActiveRecord::Associations::AssociationScope.prepend(
32
+ ::EacRailsUtils::Patches::ActiveModelAssociations::ScopeExtensionPatch
33
+ )
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRailsUtils
4
- VERSION = '0.11.1'
4
+ VERSION = '0.11.2'
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.11.1
4
+ version: 0.11.2
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: 2020-06-07 00:00:00.000000000 Z
11
+ date: 2020-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel-associations
@@ -197,6 +197,7 @@ files:
197
197
  - lib/eac_rails_utils/models/test_utils.rb
198
198
  - lib/eac_rails_utils/patches.rb
199
199
  - lib/eac_rails_utils/patches/action_controller_base.rb
200
+ - lib/eac_rails_utils/patches/active_model_associations.rb
200
201
  - lib/eac_rails_utils/version.rb
201
202
  - test/dummy/Rakefile
202
203
  - test/dummy/app/models/job.rb