eac_rails_utils 0.20.0 → 0.21.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (22) hide show
  1. checksums.yaml +4 -4
  2. data/lib/activemodel/associations.rb +3 -3
  3. data/lib/eac_rails_utils/models/tableless/strict_loading.rb +25 -0
  4. data/lib/eac_rails_utils/models/tableless.rb +1 -1
  5. data/lib/{active_model/associations → eac_rails_utils/models/tableless_associations}/active_record_reflection.rb +1 -1
  6. data/lib/{active_model/associations → eac_rails_utils/models/tableless_associations}/association_scope_extension.rb +1 -1
  7. data/lib/{active_model/associations → eac_rails_utils/models/tableless_associations}/autosave_association.rb +1 -1
  8. data/lib/eac_rails_utils/models/tableless_associations/hooks.rb +10 -0
  9. data/lib/{active_model/associations → eac_rails_utils/models/tableless_associations}/initialize_extension.rb +1 -1
  10. data/lib/{active_model/associations → eac_rails_utils/models/tableless_associations}/override_methods.rb +1 -1
  11. data/lib/eac_rails_utils/models/tableless_associations/railtie.rb +7 -0
  12. data/lib/eac_rails_utils/models/tableless_associations.rb +54 -0
  13. data/lib/eac_rails_utils/patches/active_model_associations.rb +22 -20
  14. data/lib/eac_rails_utils/patches/rails_4.rb +1 -1
  15. data/lib/eac_rails_utils/patches/rails_5_2/active_model_association_method_fix.rb +1 -1
  16. data/lib/eac_rails_utils/patches/rails_5_2.rb +1 -1
  17. data/lib/eac_rails_utils/version.rb +1 -1
  18. metadata +18 -39
  19. data/lib/active_model/associations/hooks.rb +0 -10
  20. data/lib/active_model/associations/railtie.rb +0 -7
  21. data/lib/active_model/associations.rb +0 -52
  22. /data/lib/{active_model/associations → eac_rails_utils/models/tableless_associations}/version.rb +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 424e322548e7f55ef6044d3c7e4339cd8336b272604d40678c7016b218b69494
4
- data.tar.gz: 28dd2d2a83760c49bbb30e0210e2c4aa096be75a77f7edf720cff7700f2cce9c
3
+ metadata.gz: 3aedeca11ee83d3ba78b7ed6e4018ec11ec5358279ee8aa60aeee9a704b67bc7
4
+ data.tar.gz: cf7618ee67289bbcfae473c46816562d43ed1054febf31982250b1f4c1db4184
5
5
  SHA512:
6
- metadata.gz: c7ebba5d2e7736bcefdef37c3a015130047b12ff880b2862e871b3cbd7cd1e9c9ca5bde9ab7d51def8215d4c9049bfeb2cb1a9c2ed072011dd5402e850135d59
7
- data.tar.gz: cc57e040cca6a24be309903034e74d7ff63394efd1090191f0c90b8620404ec2f31594fa4d166b40a872aa67481486c6093713722998cb77ad5d04e1298e6cea
6
+ metadata.gz: ba22996dcb260db19cfc7ea31adf12da8f530220c2426178a50b8fbd50094040aa8bb140d83d7f81b9a1ea987f6c278f0f29c8e3d9793f52e29688e0020801c6
7
+ data.tar.gz: 538843dd71b2511945bede0711f03390c0620482643b7dd0beb5bbf39fae8a79dc31c723c0a3f318379dca0734d8433b1db3462dbb5f381e6b84a49c5c4a7bfd
@@ -1,8 +1,8 @@
1
1
  require "active_model"
2
2
  require "active_record"
3
3
  require "active_support"
4
- require "active_model/associations"
5
- require "active_model/associations/hooks"
4
+ require "eac_rails_utils/models/tableless_associations"
5
+ require "eac_rails_utils/models/tableless_associations/hooks"
6
6
 
7
7
  # Load Railtie
8
8
  begin
@@ -11,5 +11,5 @@ rescue LoadError
11
11
  end
12
12
 
13
13
  if defined?(Rails)
14
- require "active_model/associations/railtie"
14
+ require "eac_rails_utils/models/tableless_associations/railtie"
15
15
  end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacRailsUtils
6
+ module Models
7
+ class Tableless
8
+ # For Rails >= '6.1'.
9
+ module StrictLoading
10
+ common_concern
11
+
12
+ class_methods do
13
+ def strict_loading?
14
+ false
15
+ end
16
+ end
17
+
18
+ # @return [Boolean]
19
+ def strict_loading?
20
+ self.class.strict_loading?
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -8,7 +8,7 @@ module EacRailsUtils
8
8
  class Tableless
9
9
  include ActiveModel::Model
10
10
  include Virtus.model
11
- include ActiveModel::Associations
11
+ include EacRailsUtils::Models::TablelessAssociations
12
12
 
13
13
  def initialize(values = {})
14
14
  super(build_attributes(values))
@@ -1,4 +1,4 @@
1
- module ActiveModel::Associations
1
+ module EacRailsUtils::Models::TablelessAssociations
2
2
  module ActiveRecordReflection
3
3
  extend ActiveSupport::Concern
4
4
 
@@ -1,4 +1,4 @@
1
- module ActiveModel::Associations
1
+ module EacRailsUtils::Models::TablelessAssociations
2
2
  module AssociationScopeExtension
3
3
  if ActiveRecord.version >= Gem::Version.new("5.0.0.beta")
4
4
  def add_constraints(scope, owner, association_klass, refl, chain_head, chain_tail)
@@ -1,4 +1,4 @@
1
- module ActiveModel::Associations
1
+ module EacRailsUtils::Models::TablelessAssociations
2
2
  module AutosaveAssociation
3
3
  extend ActiveSupport::Concern
4
4
 
@@ -0,0 +1,10 @@
1
+ module EacRailsUtils::Models::TablelessAssociations
2
+ module Hooks
3
+ def self.init
4
+ ActiveSupport.on_load(:active_record) do
5
+ require 'eac_rails_utils/models/tableless_associations/association_scope_extension'
6
+ ActiveRecord::Associations::AssociationScope.send(:prepend, EacRailsUtils::Models::TablelessAssociations::AssociationScopeExtension)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -1,4 +1,4 @@
1
- module ActiveModel::Associations
1
+ module EacRailsUtils::Models::TablelessAssociations
2
2
  module InitializeExtension
3
3
  extend ActiveSupport::Concern
4
4
 
@@ -1,4 +1,4 @@
1
- module ActiveModel::Associations
1
+ module EacRailsUtils::Models::TablelessAssociations
2
2
  module OverrideMethods
3
3
  extend ActiveSupport::Concern
4
4
 
@@ -0,0 +1,7 @@
1
+ module EacRailsUtils::Models::TablelessAssociations
2
+ class Railtie < ::Rails::Railtie #:nodoc:
3
+ initializer 'activemodel-associations' do |_|
4
+ EacRailsUtils::Models::TablelessAssociations::Hooks.init
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,54 @@
1
+ require 'eac_rails_utils/models/tableless_associations/initialize_extension'
2
+ require 'eac_rails_utils/models/tableless_associations/active_record_reflection'
3
+ require 'eac_rails_utils/models/tableless_associations/autosave_association'
4
+ require 'eac_rails_utils/models/tableless_associations/override_methods'
5
+ require 'active_record/associations/builder/has_many_for_active_model'
6
+ require 'active_record/associations/has_many_for_active_model_association'
7
+ require 'active_support/core_ext/module'
8
+
9
+ module EacRailsUtils
10
+ module Models
11
+ module TablelessAssociations
12
+ extend ActiveSupport::Concern
13
+
14
+ include InitializeExtension
15
+ include AutosaveAssociation
16
+ include ActiveRecordReflection
17
+ include OverrideMethods
18
+
19
+ included do
20
+ mattr_accessor :belongs_to_required_by_default, instance_accessor: false
21
+ end
22
+
23
+ module ClassMethods
24
+ # define association like ActiveRecord
25
+ def belongs_to(name, scope = nil, options = {})
26
+ reflection = ActiveRecord::Associations::Builder::BelongsTo.build(self, name, scope, options)
27
+ ActiveRecord::Reflection.add_reflection self, name, reflection
28
+ end
29
+
30
+ # define association like ActiveRecord
31
+ def has_many(name, scope = nil, options = {}, &extension)
32
+ options.reverse_merge!(active_model: true, target_ids: "#{name.to_s.singularize}_ids")
33
+ if scope.is_a?(Hash)
34
+ options.merge!(scope)
35
+ scope = nil
36
+ end
37
+
38
+ reflection = ActiveRecord::Associations::Builder::HasManyForActiveModel.build(self, name, scope, options, &extension)
39
+ ActiveRecord::Reflection.add_reflection self, name, reflection
40
+
41
+ mixin = generated_association_methods
42
+ mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1
43
+ def #{options[:target_ids]}=(other_ids)
44
+ @#{options[:target_ids]} = other_ids
45
+ association(:#{name}).reset
46
+ association(:#{name}).reset_scope
47
+ @#{options[:target_ids]}
48
+ end
49
+ CODE
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -4,30 +4,32 @@ require 'activemodel/associations'
4
4
  require 'eac_rails_utils/patches/rails_4'
5
5
  require 'eac_rails_utils/patches/rails_5_2'
6
6
 
7
- module ActiveModel
8
- module Associations
9
- module Hooks
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
7
+ module EacRailsUtils
8
+ module Models
9
+ module TablelessAssociations
10
+ module Hooks
11
+ class << self
12
+ def init
13
+ init_rails_4 if ::EacRailsUtils::Patches::Rails4.enabled?
14
+ init_rails_5_2 if ::EacRailsUtils::Patches::Rails52.enabled?
15
+ end
15
16
 
16
- def init_rails_4
17
- ActiveSupport.on_load(:active_record) do
18
- ActiveRecord::Associations::AssociationScope.prepend(
19
- ::EacRailsUtils::Patches::Rails4::ActiveRecordAssociationsAssociationScope
20
- )
17
+ def init_rails_4
18
+ ActiveSupport.on_load(:active_record) do
19
+ ActiveRecord::Associations::AssociationScope.prepend(
20
+ ::EacRailsUtils::Patches::Rails4::ActiveRecordAssociationsAssociationScope
21
+ )
22
+ end
21
23
  end
22
- end
23
24
 
24
- def init_rails_5_2
25
- rails_5_2_fix_activemodel_associations_methods
26
- end
25
+ def init_rails_5_2
26
+ rails_5_2_fix_activemodel_associations_methods
27
+ end
27
28
 
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)
29
+ def rails_5_2_fix_activemodel_associations_methods
30
+ %i[belongs_to has_many].each do |method|
31
+ ::EacRailsUtils::Patches::Rails52::ActiveModelAssociationMethodFix.new(method)
32
+ end
31
33
  end
32
34
  end
33
35
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_model/associations/hooks'
3
+ require 'eac_rails_utils/models/tableless_associations/hooks'
4
4
  require 'eac_ruby_utils/require_sub'
5
5
 
6
6
  module EacRailsUtils
@@ -18,7 +18,7 @@ module EacRailsUtils
18
18
  private
19
19
 
20
20
  def the_module
21
- ::ActiveModel::Associations::ClassMethods
21
+ ::EacRailsUtils::Models::TablelessAssociations::ClassMethods
22
22
  end
23
23
 
24
24
  def perform
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_model/associations/hooks'
3
+ require 'eac_rails_utils/models/tableless_associations/hooks'
4
4
  require 'eac_ruby_utils/require_sub'
5
5
 
6
6
  module EacRailsUtils
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRailsUtils
4
- VERSION = '0.20.0'
4
+ VERSION = '0.21.0'
5
5
  end
metadata CHANGED
@@ -1,43 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_rails_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.0
4
+ version: 0.21.0
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: 2023-06-24 00:00:00.000000000 Z
11
+ date: 2023-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: activemodel
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: activerecord
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
13
  - !ruby/object:Gem::Dependency
42
14
  name: bootstrap-sass
43
15
  requirement: !ruby/object:Gem::Requirement
@@ -65,6 +37,9 @@ dependencies:
65
37
  - - "~>"
66
38
  - !ruby/object:Gem::Version
67
39
  version: '0.118'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 0.118.1
68
43
  type: :runtime
69
44
  prerelease: false
70
45
  version_requirements: !ruby/object:Gem::Requirement
@@ -72,6 +47,9 @@ dependencies:
72
47
  - - "~>"
73
48
  - !ruby/object:Gem::Version
74
49
  version: '0.118'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 0.118.1
75
53
  - !ruby/object:Gem::Dependency
76
54
  name: htmlbeautifier
77
55
  requirement: !ruby/object:Gem::Requirement
@@ -220,15 +198,6 @@ files:
220
198
  - config/initializers/json.rb
221
199
  - config/locales/en.yml
222
200
  - config/locales/pt-BR.yml
223
- - lib/active_model/associations.rb
224
- - lib/active_model/associations/active_record_reflection.rb
225
- - lib/active_model/associations/association_scope_extension.rb
226
- - lib/active_model/associations/autosave_association.rb
227
- - lib/active_model/associations/hooks.rb
228
- - lib/active_model/associations/initialize_extension.rb
229
- - lib/active_model/associations/override_methods.rb
230
- - lib/active_model/associations/railtie.rb
231
- - lib/active_model/associations/version.rb
232
201
  - lib/active_record/associations/builder/has_many_for_active_model.rb
233
202
  - lib/active_record/associations/has_many_for_active_model_association.rb
234
203
  - lib/activemodel/associations.rb
@@ -243,6 +212,16 @@ files:
243
212
  - lib/eac_rails_utils/models/tableless/attributes.rb
244
213
  - lib/eac_rails_utils/models/tableless/build_attributes.rb
245
214
  - lib/eac_rails_utils/models/tableless/columns.rb
215
+ - lib/eac_rails_utils/models/tableless/strict_loading.rb
216
+ - lib/eac_rails_utils/models/tableless_associations.rb
217
+ - lib/eac_rails_utils/models/tableless_associations/active_record_reflection.rb
218
+ - lib/eac_rails_utils/models/tableless_associations/association_scope_extension.rb
219
+ - lib/eac_rails_utils/models/tableless_associations/autosave_association.rb
220
+ - lib/eac_rails_utils/models/tableless_associations/hooks.rb
221
+ - lib/eac_rails_utils/models/tableless_associations/initialize_extension.rb
222
+ - lib/eac_rails_utils/models/tableless_associations/override_methods.rb
223
+ - lib/eac_rails_utils/models/tableless_associations/railtie.rb
224
+ - lib/eac_rails_utils/models/tableless_associations/version.rb
246
225
  - lib/eac_rails_utils/models/test_utils.rb
247
226
  - lib/eac_rails_utils/models/validations.rb
248
227
  - lib/eac_rails_utils/patches.rb
@@ -1,10 +0,0 @@
1
- module ActiveModel::Associations
2
- module Hooks
3
- def self.init
4
- ActiveSupport.on_load(:active_record) do
5
- require 'active_model/associations/association_scope_extension'
6
- ActiveRecord::Associations::AssociationScope.send(:prepend, ActiveModel::Associations::AssociationScopeExtension)
7
- end
8
- end
9
- end
10
- end
@@ -1,7 +0,0 @@
1
- module ActiveModel::Associations
2
- class Railtie < ::Rails::Railtie #:nodoc:
3
- initializer 'activemodel-associations' do |_|
4
- ActiveModel::Associations::Hooks.init
5
- end
6
- end
7
- end
@@ -1,52 +0,0 @@
1
- require 'active_model/associations/initialize_extension'
2
- require 'active_model/associations/active_record_reflection'
3
- require 'active_model/associations/autosave_association'
4
- require 'active_model/associations/override_methods'
5
- require 'active_record/associations/builder/has_many_for_active_model'
6
- require 'active_record/associations/has_many_for_active_model_association'
7
- require 'active_support/core_ext/module'
8
-
9
- module ActiveModel
10
- module Associations
11
- extend ActiveSupport::Concern
12
-
13
- include InitializeExtension
14
- include AutosaveAssociation
15
- include ActiveRecordReflection
16
- include OverrideMethods
17
-
18
- included do
19
- mattr_accessor :belongs_to_required_by_default, instance_accessor: false
20
- end
21
-
22
- module ClassMethods
23
- # define association like ActiveRecord
24
- def belongs_to(name, scope = nil, options = {})
25
- reflection = ActiveRecord::Associations::Builder::BelongsTo.build(self, name, scope, options)
26
- ActiveRecord::Reflection.add_reflection self, name, reflection
27
- end
28
-
29
- # define association like ActiveRecord
30
- def has_many(name, scope = nil, options = {}, &extension)
31
- options.reverse_merge!(active_model: true, target_ids: "#{name.to_s.singularize}_ids")
32
- if scope.is_a?(Hash)
33
- options.merge!(scope)
34
- scope = nil
35
- end
36
-
37
- reflection = ActiveRecord::Associations::Builder::HasManyForActiveModel.build(self, name, scope, options, &extension)
38
- ActiveRecord::Reflection.add_reflection self, name, reflection
39
-
40
- mixin = generated_association_methods
41
- mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1
42
- def #{options[:target_ids]}=(other_ids)
43
- @#{options[:target_ids]} = other_ids
44
- association(:#{name}).reset
45
- association(:#{name}).reset_scope
46
- @#{options[:target_ids]}
47
- end
48
- CODE
49
- end
50
- end
51
- end
52
- end