eac_rails_utils 0.20.0 → 0.22.0

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.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/lib/activemodel/associations.rb +3 -3
  3. data/lib/eac_rails_utils/engine_helper.rb +12 -0
  4. data/lib/eac_rails_utils/menus/action.rb +33 -0
  5. data/lib/eac_rails_utils/menus/group.rb +73 -0
  6. data/lib/eac_rails_utils/menus/node.rb +50 -0
  7. data/lib/eac_rails_utils/menus.rb +9 -0
  8. data/lib/eac_rails_utils/models/tableless/strict_loading.rb +25 -0
  9. data/lib/eac_rails_utils/models/tableless.rb +1 -1
  10. data/lib/{active_model/associations → eac_rails_utils/models/tableless_associations}/active_record_reflection.rb +1 -1
  11. data/lib/{active_model/associations → eac_rails_utils/models/tableless_associations}/association_scope_extension.rb +1 -1
  12. data/lib/{active_model/associations → eac_rails_utils/models/tableless_associations}/autosave_association.rb +1 -1
  13. data/lib/eac_rails_utils/models/tableless_associations/hooks.rb +10 -0
  14. data/lib/{active_model/associations → eac_rails_utils/models/tableless_associations}/initialize_extension.rb +1 -1
  15. data/lib/{active_model/associations → eac_rails_utils/models/tableless_associations}/override_methods.rb +1 -1
  16. data/lib/eac_rails_utils/models/tableless_associations/railtie.rb +7 -0
  17. data/lib/eac_rails_utils/models/tableless_associations.rb +54 -0
  18. data/lib/eac_rails_utils/patches/active_model/naming.rb +17 -0
  19. data/lib/eac_rails_utils/patches/active_model.rb +4 -0
  20. data/lib/eac_rails_utils/patches/active_model_associations.rb +22 -20
  21. data/lib/eac_rails_utils/patches/application.rb +12 -0
  22. data/lib/eac_rails_utils/patches/rails_4.rb +1 -1
  23. data/lib/eac_rails_utils/patches/rails_5_2/active_model_association_method_fix.rb +1 -1
  24. data/lib/eac_rails_utils/patches/rails_5_2.rb +1 -1
  25. data/lib/eac_rails_utils/version.rb +1 -1
  26. metadata +27 -41
  27. data/lib/active_model/associations/hooks.rb +0 -10
  28. data/lib/active_model/associations/railtie.rb +0 -7
  29. data/lib/active_model/associations.rb +0 -52
  30. /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: 2d70491a91afe401a5ff75d1ecf1d1820e9164bb725d33ecbf5a233508e70faa
4
+ data.tar.gz: 59c3693a4563491e0da78bf4496d620c75025b7b70fb4cda760405ac04c3f436
5
5
  SHA512:
6
- metadata.gz: c7ebba5d2e7736bcefdef37c3a015130047b12ff880b2862e871b3cbd7cd1e9c9ca5bde9ab7d51def8215d4c9049bfeb2cb1a9c2ed072011dd5402e850135d59
7
- data.tar.gz: cc57e040cca6a24be309903034e74d7ff63394efd1090191f0c90b8620404ec2f31594fa4d166b40a872aa67481486c6093713722998cb77ad5d04e1298e6cea
6
+ metadata.gz: ed28ed741a6dc380f97f1b3a1af9afaba32baebeee1c06ccf81790eab178ac8eadf022051a3dd5dffd98c01bf421fc749ce69d4db8b4a078c8d347795a286949
7
+ data.tar.gz: d5b26dc72e4a8d36e9b609b606a95264432c81e612a08fa705c40da2db94fe3e6ba23108121f170dcd1f395cea969133c6799ab15ccb6520e0f3a8a22e2ed025
@@ -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
@@ -4,6 +4,13 @@ require 'eac_ruby_utils/core_ext'
4
4
 
5
5
  module EacRailsUtils
6
6
  module EngineHelper
7
+ class << self
8
+ # @return [EacRailsUtils::Menus::Group]
9
+ def root_menu
10
+ @root_menu ||= ::EacRailsUtils::Menus::Group.new(:root)
11
+ end
12
+ end
13
+
7
14
  common_concern do
8
15
  append_autoload_paths
9
16
  append_self_migrations
@@ -21,6 +28,11 @@ module EacRailsUtils
21
28
  end
22
29
  end
23
30
  end
31
+
32
+ # @return [EacRailsUtils::Menus::Group]
33
+ def root_menu
34
+ ::EacRailsUtils::EnginesHelper.root_menu
35
+ end
24
36
  end
25
37
  end
26
38
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_rails_utils/menus/node'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module EacRailsUtils
7
+ module Menus
8
+ class Action < ::EacRailsUtils::Menus::Node
9
+ common_constructor :path, :parent_group, super_args: -> { [parent_group] } do
10
+ self.path = [parent_group.path_first_node] + path if path.size < 2
11
+ end
12
+
13
+ # @return [Symbol]
14
+ def key
15
+ path.map(&:to_s).join('_').to_sym
16
+ end
17
+
18
+ # @param view [ActionView::Base]
19
+ # @return [Array]
20
+ def to_dropdown_menu_entries(view)
21
+ [view_path(view)]
22
+ end
23
+
24
+ # @param view [ActionView::Base]
25
+ # @return [String]
26
+ def view_path(view)
27
+ path.each_with_index.inject(view) do |a, e|
28
+ a.send(e[1] == path.count - 1 ? "#{e[0]}_path" : e[0])
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_rails_utils/menus/action'
4
+ require 'eac_rails_utils/menus/node'
5
+ require 'eac_ruby_utils/core_ext'
6
+
7
+ module EacRailsUtils
8
+ module Menus
9
+ class Group < ::EacRailsUtils::Menus::Node
10
+ class << self
11
+ # @param key [Object]
12
+ # @return [Symbol]
13
+ def sanitize_key(key)
14
+ key.to_sym
15
+ end
16
+ end
17
+
18
+ DEFAULT_PATH_FIRST_NODE = :main_app
19
+ SELF_LABEL_TRANSLATE_KEY_PART = '__self'
20
+
21
+ common_constructor :key, :parent_group, :path_first_node, default: [nil],
22
+ super_args: -> { [parent_group] } do
23
+ self.key = self.class.sanitize_key(key)
24
+ self.path_first_node ||= DEFAULT_PATH_FIRST_NODE
25
+ end
26
+
27
+ # @param path [Array<Symbol>]
28
+ # @return [EacRailsUtils::Menus::Action]
29
+ def action(*path)
30
+ child_action = ::EacRailsUtils::Menus::Action.new(path, self)
31
+ actions[child_action.key] ||= child_action
32
+ end
33
+
34
+ # @return [Array<EacRailsUtils::Menus::Node>]
35
+ def children
36
+ (groups.values + actions.values).sort
37
+ end
38
+
39
+ # @return [EacRailsUtils::Menus::Group]
40
+ def group(group_key, path_first_node = nil)
41
+ child_group = self.class.new(group_key, self, path_first_node)
42
+ groups[child_group.key] ||= child_group
43
+ end
44
+
45
+ # @return [String]
46
+ def label_translate_key
47
+ [super, SELF_LABEL_TRANSLATE_KEY_PART].join(TRANSLATE_KEY_SEPARATOR)
48
+ end
49
+
50
+ # @param view [ActionView::Base]
51
+ # @return [Hash]
52
+ def to_dropdown_menu_entries(view)
53
+ children.inject({}) do |a, e|
54
+ a.merge(e.label => e.to_dropdown_menu_entries(view))
55
+ end
56
+ end
57
+
58
+ def within
59
+ yield(self)
60
+ end
61
+
62
+ private
63
+
64
+ def actions
65
+ @actions ||= {}
66
+ end
67
+
68
+ def groups
69
+ @groups ||= {}
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacRailsUtils
6
+ module Menus
7
+ class Node
8
+ LABEL_TRANSLATE_KEY_PREFIX = 'eac_rails_utils.menus'
9
+ TRANSLATE_KEY_SEPARATOR = '.'
10
+
11
+ acts_as_abstract :key
12
+ common_constructor :parent_group
13
+ compare_by :label
14
+ attr_reader :custom_label
15
+
16
+ # @return [String]
17
+ def auto_label
18
+ ::I18n.t(label_translate_key)
19
+ end
20
+
21
+ # @param custom_label [String, nil]
22
+ # @return [String, self]
23
+ def label(custom_label = nil)
24
+ if custom_label.present?
25
+ self.custom_label = custom_label
26
+ self
27
+ else
28
+ (self.custom_label || auto_label).call_if_proc
29
+ end
30
+ end
31
+
32
+ # @return [String]
33
+ def label_translate_key
34
+ parent_label_translate_key
35
+ end
36
+
37
+ # @return [String]
38
+ def parent_label_translate_key
39
+ [
40
+ parent_group.if_present(LABEL_TRANSLATE_KEY_PREFIX, &:parent_label_translate_key),
41
+ key
42
+ ].join(TRANSLATE_KEY_SEPARATOR)
43
+ end
44
+
45
+ private
46
+
47
+ attr_writer :custom_label
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacRailsUtils
6
+ module Menus
7
+ require_sub __FILE__
8
+ end
9
+ 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
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_model/naming'
4
+
5
+ module ActiveModel
6
+ module Naming
7
+ # @return [String]
8
+ def plural_name
9
+ model_name.human(count: 2)
10
+ end
11
+
12
+ # @return [String]
13
+ def singular_name
14
+ model_name.human(count: 1)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+ ::EacRubyUtils.require_sub __FILE__
@@ -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
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_rails_utils/menus/group'
4
+
5
+ module Rails
6
+ class Application
7
+ # @return [EacRailsUtils::Menus::Group]
8
+ def root_menu
9
+ @root_menu ||= ::EacRailsUtils::Menus::Group.new(:root, nil)
10
+ end
11
+ end
12
+ 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.22.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.22.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-09-18 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
@@ -64,14 +36,20 @@ dependencies:
64
36
  requirements:
65
37
  - - "~>"
66
38
  - !ruby/object:Gem::Version
67
- version: '0.118'
39
+ version: '0.119'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 0.119.2
68
43
  type: :runtime
69
44
  prerelease: false
70
45
  version_requirements: !ruby/object:Gem::Requirement
71
46
  requirements:
72
47
  - - "~>"
73
48
  - !ruby/object:Gem::Version
74
- version: '0.118'
49
+ version: '0.119'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 0.119.2
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
@@ -236,6 +205,10 @@ files:
236
205
  - lib/eac_rails_utils/engine.rb
237
206
  - lib/eac_rails_utils/engine_helper.rb
238
207
  - lib/eac_rails_utils/htmlbeautifier.rb
208
+ - lib/eac_rails_utils/menus.rb
209
+ - lib/eac_rails_utils/menus/action.rb
210
+ - lib/eac_rails_utils/menus/group.rb
211
+ - lib/eac_rails_utils/menus/node.rb
239
212
  - lib/eac_rails_utils/models.rb
240
213
  - lib/eac_rails_utils/models/fetch_errors.rb
241
214
  - lib/eac_rails_utils/models/inequality_queries.rb
@@ -243,10 +216,23 @@ files:
243
216
  - lib/eac_rails_utils/models/tableless/attributes.rb
244
217
  - lib/eac_rails_utils/models/tableless/build_attributes.rb
245
218
  - lib/eac_rails_utils/models/tableless/columns.rb
219
+ - lib/eac_rails_utils/models/tableless/strict_loading.rb
220
+ - lib/eac_rails_utils/models/tableless_associations.rb
221
+ - lib/eac_rails_utils/models/tableless_associations/active_record_reflection.rb
222
+ - lib/eac_rails_utils/models/tableless_associations/association_scope_extension.rb
223
+ - lib/eac_rails_utils/models/tableless_associations/autosave_association.rb
224
+ - lib/eac_rails_utils/models/tableless_associations/hooks.rb
225
+ - lib/eac_rails_utils/models/tableless_associations/initialize_extension.rb
226
+ - lib/eac_rails_utils/models/tableless_associations/override_methods.rb
227
+ - lib/eac_rails_utils/models/tableless_associations/railtie.rb
228
+ - lib/eac_rails_utils/models/tableless_associations/version.rb
246
229
  - lib/eac_rails_utils/models/test_utils.rb
247
230
  - lib/eac_rails_utils/models/validations.rb
248
231
  - lib/eac_rails_utils/patches.rb
232
+ - lib/eac_rails_utils/patches/active_model.rb
233
+ - lib/eac_rails_utils/patches/active_model/naming.rb
249
234
  - lib/eac_rails_utils/patches/active_model_associations.rb
235
+ - lib/eac_rails_utils/patches/application.rb
250
236
  - lib/eac_rails_utils/patches/numeric.rb
251
237
  - lib/eac_rails_utils/patches/numeric/number_helper.rb
252
238
  - lib/eac_rails_utils/patches/rails_4.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