eac_rails_utils 0.21.0 → 0.22.1
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 +4 -4
- data/lib/eac_rails_utils/engine_helper.rb +12 -0
- data/lib/eac_rails_utils/menus/action.rb +33 -0
- data/lib/eac_rails_utils/menus/group.rb +73 -0
- data/lib/eac_rails_utils/menus/node.rb +50 -0
- data/lib/eac_rails_utils/menus.rb +9 -0
- data/lib/eac_rails_utils/models/tableless_associations/active_record_reflection.rb +34 -28
- data/lib/eac_rails_utils/models/tableless_associations/association_scope_extension.rb +23 -17
- data/lib/eac_rails_utils/models/tableless_associations/autosave_association.rb +13 -7
- data/lib/eac_rails_utils/models/tableless_associations/hooks.rb +14 -6
- data/lib/eac_rails_utils/models/tableless_associations/initialize_extension.rb +16 -10
- data/lib/eac_rails_utils/models/tableless_associations/override_methods.rb +98 -81
- data/lib/eac_rails_utils/models/tableless_associations/railtie.rb +10 -4
- data/lib/eac_rails_utils/models/tableless_associations.rb +7 -3
- data/lib/eac_rails_utils/patches/active_model/naming.rb +17 -0
- data/lib/eac_rails_utils/patches/active_model.rb +4 -0
- data/lib/eac_rails_utils/patches/application.rb +12 -0
- data/lib/eac_rails_utils/version.rb +1 -1
- metadata +13 -7
- data/lib/eac_rails_utils/models/tableless_associations/version.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a88b255d31abb1059b16e75e33cb24b9ba2ad64a3d35afd63e27bc1d01dbbbe
|
4
|
+
data.tar.gz: b50b1587013cb361fe0eb2d7d56ee46dd5bdd87ed6aacf836aee7867ec7c152e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1249f9ba2a9598117e86de27b315fdd2f6f0f55330ee39916ea9e03f25c97b9c966a99a476628a1dfda677ea14b518cdf7478ad21eafc41868b4bcf4222fe65e
|
7
|
+
data.tar.gz: a7def8aa5c32a906ecae3e29b5c42ba669f962c368ad3ae01153de142ce74cc3f3da22f9090cc4d9d97fa359080ed414985be9879b8d3f42ec476e7b6f0dcae9
|
@@ -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
|
@@ -1,36 +1,42 @@
|
|
1
|
-
|
2
|
-
module ActiveRecordReflection
|
3
|
-
extend ActiveSupport::Concern
|
1
|
+
# frozen_string_literal: true
|
4
2
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
class_attribute :reflections
|
11
|
-
self.reflections = {}
|
12
|
-
end
|
13
|
-
end
|
3
|
+
module EacRailsUtils
|
4
|
+
module Models
|
5
|
+
module TablelessAssociations
|
6
|
+
module ActiveRecordReflection
|
7
|
+
extend ActiveSupport::Concern
|
14
8
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
9
|
+
included do
|
10
|
+
if ActiveRecord.version >= Gem::Version.new('4.1.2')
|
11
|
+
class_attribute :_reflections
|
12
|
+
self._reflections = ActiveSupport::HashWithIndifferentAccess.new
|
13
|
+
else
|
14
|
+
class_attribute :reflections
|
15
|
+
self.reflections = {}
|
22
16
|
end
|
23
|
-
|
24
|
-
self.reflections = self.reflections.merge(name => reflection)
|
25
|
-
reflection
|
26
17
|
end
|
27
|
-
end
|
28
18
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
19
|
+
module ClassMethods
|
20
|
+
if ActiveRecord.version < Gem::Version.new('4.1')
|
21
|
+
def create_reflection(macro, name, scope, options, active_record)
|
22
|
+
case macro
|
23
|
+
when :has_many, :belongs_to
|
24
|
+
klass = ActiveRecord::Reflection::AssociationReflection
|
25
|
+
reflection = klass.new(macro, name, scope, options, active_record)
|
26
|
+
end
|
27
|
+
|
28
|
+
self.reflections = reflections.merge(name => reflection)
|
29
|
+
reflection
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def reflect_on_association(association)
|
34
|
+
if ActiveRecord.version >= Gem::Version.new('4.1.2')
|
35
|
+
_reflections[association.to_s]
|
36
|
+
else
|
37
|
+
reflections[association]
|
38
|
+
end
|
39
|
+
end
|
34
40
|
end
|
35
41
|
end
|
36
42
|
end
|
@@ -1,22 +1,28 @@
|
|
1
|
-
|
2
|
-
module AssociationScopeExtension
|
3
|
-
if ActiveRecord.version >= Gem::Version.new("5.0.0.beta")
|
4
|
-
def add_constraints(scope, owner, association_klass, refl, chain_head, chain_tail)
|
5
|
-
if refl.options[:active_model]
|
6
|
-
target_ids = refl.options[:target_ids]
|
7
|
-
return scope.where(id: owner[target_ids])
|
8
|
-
end
|
1
|
+
# frozen_string_literal: true
|
9
2
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
if
|
15
|
-
|
16
|
-
|
17
|
-
|
3
|
+
module EacRailsUtils
|
4
|
+
module Models
|
5
|
+
module TablelessAssociations
|
6
|
+
module AssociationScopeExtension
|
7
|
+
if ActiveRecord.version >= Gem::Version.new('5.0.0.beta')
|
8
|
+
def add_constraints(scope, owner, association_klass, refl, chain_head, chain_tail) # rubocop:disable Metrics/ParameterLists
|
9
|
+
if refl.options[:active_model]
|
10
|
+
target_ids = refl.options[:target_ids]
|
11
|
+
return scope.where(id: owner[target_ids])
|
12
|
+
end
|
18
13
|
|
19
|
-
|
14
|
+
super
|
15
|
+
end
|
16
|
+
else
|
17
|
+
def add_constraints(scope, owner, assoc_klass, refl, tracker)
|
18
|
+
if refl.options[:active_model]
|
19
|
+
target_ids = refl.options[:target_ids]
|
20
|
+
return scope.where(id: owner[target_ids])
|
21
|
+
end
|
22
|
+
|
23
|
+
super
|
24
|
+
end
|
25
|
+
end
|
20
26
|
end
|
21
27
|
end
|
22
28
|
end
|
@@ -1,12 +1,18 @@
|
|
1
|
-
|
2
|
-
module AutosaveAssociation
|
3
|
-
extend ActiveSupport::Concern
|
1
|
+
# frozen_string_literal: true
|
4
2
|
|
5
|
-
|
3
|
+
module EacRailsUtils
|
4
|
+
module Models
|
5
|
+
module TablelessAssociations
|
6
|
+
module AutosaveAssociation
|
7
|
+
extend ActiveSupport::Concern
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
9
|
+
include ActiveRecord::AutosaveAssociation
|
10
|
+
|
11
|
+
included do
|
12
|
+
extend ActiveModel::Callbacks
|
13
|
+
define_model_callbacks :save, :create, :update
|
14
|
+
end
|
15
|
+
end
|
10
16
|
end
|
11
17
|
end
|
12
18
|
end
|
@@ -1,9 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacRailsUtils
|
4
|
+
module Models
|
5
|
+
module TablelessAssociations
|
6
|
+
module Hooks
|
7
|
+
def self.init
|
8
|
+
ActiveSupport.on_load(:active_record) do
|
9
|
+
require 'eac_rails_utils/models/tableless_associations/association_scope_extension'
|
10
|
+
ActiveRecord::Associations::AssociationScope.prepend(
|
11
|
+
EacRailsUtils::Models::TablelessAssociations::AssociationScopeExtension
|
12
|
+
)
|
13
|
+
end
|
14
|
+
end
|
7
15
|
end
|
8
16
|
end
|
9
17
|
end
|
@@ -1,15 +1,21 @@
|
|
1
|
-
|
2
|
-
module InitializeExtension
|
3
|
-
extend ActiveSupport::Concern
|
1
|
+
# frozen_string_literal: true
|
4
2
|
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
module EacRailsUtils
|
4
|
+
module Models
|
5
|
+
module TablelessAssociations
|
6
|
+
module InitializeExtension
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
prepend WithAssociationCache
|
11
|
+
end
|
8
12
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
+
module WithAssociationCache
|
14
|
+
def initialize(*args)
|
15
|
+
@association_cache = {}
|
16
|
+
super
|
17
|
+
end
|
18
|
+
end
|
13
19
|
end
|
14
20
|
end
|
15
21
|
end
|
@@ -1,111 +1,128 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
module
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacRailsUtils
|
4
|
+
module Models
|
5
|
+
module TablelessAssociations
|
6
|
+
module OverrideMethods
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def generated_association_methods
|
11
|
+
@generated_association_methods ||= begin
|
12
|
+
mod = const_set(:GeneratedAssociationMethods, Module.new)
|
13
|
+
include mod
|
14
|
+
mod
|
15
|
+
end
|
16
|
+
end
|
17
|
+
alias generated_feature_methods generated_association_methods \
|
18
|
+
if ActiveRecord.version < Gem::Version.new('4.1')
|
15
19
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
+
# override
|
21
|
+
def dangerous_attribute_method?(_name)
|
22
|
+
false
|
23
|
+
end
|
20
24
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
+
# dummy table name
|
26
|
+
def pluralize_table_names
|
27
|
+
to_s.pluralize
|
28
|
+
end
|
25
29
|
|
26
|
-
|
27
|
-
|
28
|
-
|
30
|
+
def clear_reflections_cache
|
31
|
+
@__reflections = nil
|
32
|
+
end
|
29
33
|
|
30
|
-
|
31
|
-
|
32
|
-
|
34
|
+
def default_scopes
|
35
|
+
[]
|
36
|
+
end
|
37
|
+
|
38
|
+
protected
|
33
39
|
|
34
|
-
|
40
|
+
def compute_type(type_name)
|
41
|
+
if type_name.match(/^::/)
|
42
|
+
# If the type is prefixed with a scope operator then we assume that
|
43
|
+
# the type_name is an absolute reference.
|
44
|
+
ActiveSupport::Dependencies.constantize(type_name)
|
45
|
+
else
|
46
|
+
compute_type_from_candidates(type_name)
|
47
|
+
end
|
48
|
+
end
|
35
49
|
|
36
|
-
def compute_type(type_name)
|
37
|
-
if type_name.match(/^::/)
|
38
|
-
# If the type is prefixed with a scope operator then we assume that
|
39
|
-
# the type_name is an absolute reference.
|
40
|
-
ActiveSupport::Dependencies.constantize(type_name)
|
41
|
-
else
|
42
50
|
# Build a list of candidates to search for
|
43
|
-
|
44
|
-
|
45
|
-
|
51
|
+
def compute_type_candidates(type_name)
|
52
|
+
candidates = []
|
53
|
+
name.scan(/::|$/) { candidates.unshift "#{$`}::#{type_name}" }
|
54
|
+
candidates << type_name
|
55
|
+
end
|
46
56
|
|
47
|
-
|
48
|
-
|
57
|
+
def compute_type_from_candidates(type_name)
|
58
|
+
compute_type_candidates(type_name).each do |candidate|
|
49
59
|
constant = ActiveSupport::Dependencies.constantize(candidate)
|
50
60
|
return constant if candidate == constant.to_s
|
51
61
|
# We don't want to swallow NoMethodError < NameError errors
|
52
62
|
rescue NoMethodError
|
53
63
|
raise
|
54
|
-
rescue NameError
|
64
|
+
rescue NameError # rubocop:disable Lint/SuppressedException
|
55
65
|
end
|
56
|
-
end
|
57
66
|
|
58
|
-
|
67
|
+
raise NameError.new("uninitialized constant #{candidates.first}", candidates.first)
|
68
|
+
end
|
59
69
|
end
|
60
|
-
end
|
61
|
-
end
|
62
70
|
|
63
|
-
|
64
|
-
|
65
|
-
|
71
|
+
# use by association accessor
|
72
|
+
def association(name) #:nodoc:
|
73
|
+
association = association_instance_get(name)
|
74
|
+
|
75
|
+
if association.nil?
|
76
|
+
association = association_by_reflection(name)
|
77
|
+
association_instance_set(name, association)
|
78
|
+
end
|
66
79
|
|
67
|
-
|
68
|
-
reflection = self.class.reflect_on_association(name)
|
69
|
-
if reflection.options[:active_model]
|
70
|
-
association = ActiveRecord::Associations::HasManyForActiveModelAssociation.new(self, reflection)
|
71
|
-
else
|
72
|
-
association = reflection.association_class.new(self, reflection)
|
80
|
+
association
|
73
81
|
end
|
74
|
-
association_instance_set(name, association)
|
75
|
-
end
|
76
82
|
|
77
|
-
|
78
|
-
|
83
|
+
def read_attribute(name)
|
84
|
+
send(name)
|
85
|
+
end
|
86
|
+
alias _read_attribute read_attribute
|
79
87
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
88
|
+
# dummy
|
89
|
+
def new_record?
|
90
|
+
false
|
91
|
+
end
|
84
92
|
|
85
|
-
|
86
|
-
def new_record?
|
87
|
-
false
|
88
|
-
end
|
93
|
+
private
|
89
94
|
|
90
|
-
|
95
|
+
def association_by_reflection(name)
|
96
|
+
reflection = self.class.reflect_on_association(name)
|
97
|
+
if reflection.options[:active_model]
|
98
|
+
::ActiveRecord::Associations::HasManyForActiveModelAssociation.new(self, reflection)
|
99
|
+
else
|
100
|
+
reflection.association_class.new(self, reflection)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# override
|
105
|
+
def validate_collection_association(reflection)
|
106
|
+
return unless (association = association_instance_get(reflection.name))
|
91
107
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
108
|
+
if (records = associated_records_to_validate_or_save(
|
109
|
+
association,
|
110
|
+
false, reflection.options[:autosave]
|
111
|
+
))
|
112
|
+
records.each { |record| association_valid?(reflection, record) }
|
113
|
+
end
|
97
114
|
end
|
98
|
-
end
|
99
|
-
end
|
100
115
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
116
|
+
# use in Rails internal
|
117
|
+
def association_instance_get(name)
|
118
|
+
@association_cache[name]
|
119
|
+
end
|
105
120
|
|
106
|
-
|
107
|
-
|
108
|
-
|
121
|
+
# use in Rails internal
|
122
|
+
def association_instance_set(name, association)
|
123
|
+
@association_cache[name] = association
|
124
|
+
end
|
125
|
+
end
|
109
126
|
end
|
110
127
|
end
|
111
128
|
end
|
@@ -1,7 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacRailsUtils
|
4
|
+
module Models
|
5
|
+
module TablelessAssociations
|
6
|
+
class Railtie < ::Rails::Railtie #:nodoc:
|
7
|
+
initializer 'activemodel-associations' do |_|
|
8
|
+
EacRailsUtils::Models::TablelessAssociations::Hooks.init
|
9
|
+
end
|
10
|
+
end
|
5
11
|
end
|
6
12
|
end
|
7
13
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'eac_rails_utils/models/tableless_associations/initialize_extension'
|
2
4
|
require 'eac_rails_utils/models/tableless_associations/active_record_reflection'
|
3
5
|
require 'eac_rails_utils/models/tableless_associations/autosave_association'
|
@@ -23,19 +25,21 @@ module EacRailsUtils
|
|
23
25
|
module ClassMethods
|
24
26
|
# define association like ActiveRecord
|
25
27
|
def belongs_to(name, scope = nil, options = {})
|
26
|
-
reflection = ActiveRecord::Associations::Builder::BelongsTo
|
28
|
+
reflection = ActiveRecord::Associations::Builder::BelongsTo
|
29
|
+
.build(self, name, scope, options)
|
27
30
|
ActiveRecord::Reflection.add_reflection self, name, reflection
|
28
31
|
end
|
29
32
|
|
30
33
|
# define association like ActiveRecord
|
31
|
-
def has_many(name, scope = nil, options = {}, &extension)
|
34
|
+
def has_many(name, scope = nil, options = {}, &extension) # rubocop:disable Naming/PredicateName
|
32
35
|
options.reverse_merge!(active_model: true, target_ids: "#{name.to_s.singularize}_ids")
|
33
36
|
if scope.is_a?(Hash)
|
34
37
|
options.merge!(scope)
|
35
38
|
scope = nil
|
36
39
|
end
|
37
40
|
|
38
|
-
reflection = ActiveRecord::Associations::Builder::HasManyForActiveModel
|
41
|
+
reflection = ActiveRecord::Associations::Builder::HasManyForActiveModel
|
42
|
+
.build(self, name, scope, options, &extension)
|
39
43
|
ActiveRecord::Reflection.add_reflection self, name, reflection
|
40
44
|
|
41
45
|
mixin = generated_association_methods
|
@@ -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
|
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.
|
4
|
+
version: 0.22.1
|
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-
|
11
|
+
date: 2023-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bootstrap-sass
|
@@ -36,20 +36,20 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: '0.
|
39
|
+
version: '0.119'
|
40
40
|
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: 0.
|
42
|
+
version: 0.119.2
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
47
|
- - "~>"
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: '0.
|
49
|
+
version: '0.119'
|
50
50
|
- - ">="
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: 0.
|
52
|
+
version: 0.119.2
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: htmlbeautifier
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -205,6 +205,10 @@ files:
|
|
205
205
|
- lib/eac_rails_utils/engine.rb
|
206
206
|
- lib/eac_rails_utils/engine_helper.rb
|
207
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
|
208
212
|
- lib/eac_rails_utils/models.rb
|
209
213
|
- lib/eac_rails_utils/models/fetch_errors.rb
|
210
214
|
- lib/eac_rails_utils/models/inequality_queries.rb
|
@@ -221,11 +225,13 @@ files:
|
|
221
225
|
- lib/eac_rails_utils/models/tableless_associations/initialize_extension.rb
|
222
226
|
- lib/eac_rails_utils/models/tableless_associations/override_methods.rb
|
223
227
|
- lib/eac_rails_utils/models/tableless_associations/railtie.rb
|
224
|
-
- lib/eac_rails_utils/models/tableless_associations/version.rb
|
225
228
|
- lib/eac_rails_utils/models/test_utils.rb
|
226
229
|
- lib/eac_rails_utils/models/validations.rb
|
227
230
|
- lib/eac_rails_utils/patches.rb
|
231
|
+
- lib/eac_rails_utils/patches/active_model.rb
|
232
|
+
- lib/eac_rails_utils/patches/active_model/naming.rb
|
228
233
|
- lib/eac_rails_utils/patches/active_model_associations.rb
|
234
|
+
- lib/eac_rails_utils/patches/application.rb
|
229
235
|
- lib/eac_rails_utils/patches/numeric.rb
|
230
236
|
- lib/eac_rails_utils/patches/numeric/number_helper.rb
|
231
237
|
- lib/eac_rails_utils/patches/rails_4.rb
|