mutils 0.2.37 → 1.1.2
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/.github/dependabot.yml +10 -0
- data/.gitignore +1 -0
- data/.huskyrc +7 -0
- data/.rspec +0 -1
- data/.rubocop.yml +1 -2
- data/.rubocop_todo.yml +2 -0
- data/.travis.yml +13 -2
- data/CHANGELOG.md +52 -16
- data/Gemfile +6 -0
- data/Gemfile.lock +35 -1
- data/README.md +31 -8
- data/SECURITY.md +13 -0
- data/Version +1 -0
- data/commitlint.config.js +1 -0
- data/gemdeploy.sh +10 -0
- data/lib/mutils.rb +1 -0
- data/lib/mutils/lib/helper.rb +14 -4
- data/lib/mutils/lib/result_hash.rb +25 -0
- data/lib/mutils/serialization/base_serializer.rb +0 -8
- data/lib/mutils/serialization/methods/attributes.rb +52 -0
- data/lib/mutils/serialization/methods/main.rb +27 -0
- data/lib/mutils/serialization/methods/relations.rb +40 -0
- data/lib/mutils/serialization/results/attributes.rb +24 -0
- data/lib/mutils/serialization/results/main.rb +59 -0
- data/lib/mutils/serialization/results/relations.rb +23 -0
- data/lib/mutils/serialization/serialization_methods.rb +6 -79
- data/lib/mutils/serialization/serialization_results.rb +6 -77
- data/lib/mutils/version.rb +1 -1
- data/mutils.gemspec +1 -3
- data/package-lock.json +7019 -0
- data/package.json +94 -0
- metadata +19 -49
- data/.github/workflows/gempush.yml +0 -28
- data/.mergify.yml +0 -8
- data/Makefile +0 -8
data/lib/mutils/lib/helper.rb
CHANGED
|
@@ -4,20 +4,30 @@ require 'singleton'
|
|
|
4
4
|
# module Mutils
|
|
5
5
|
module Mutils
|
|
6
6
|
module Lib
|
|
7
|
-
#
|
|
7
|
+
# Helper: caching expensive repetitive operations
|
|
8
8
|
class Helper
|
|
9
9
|
include Singleton
|
|
10
10
|
|
|
11
11
|
def initialize
|
|
12
12
|
self.inflector_object = Dry::Inflector.new
|
|
13
|
+
self.pluralize_cache = {}
|
|
14
|
+
self.underscore_cache = {}
|
|
15
|
+
self.constantize_cache = {}
|
|
13
16
|
end
|
|
14
17
|
|
|
15
18
|
def underscore(string)
|
|
16
|
-
inflector_object.underscore string
|
|
19
|
+
underscore_cache[string] = inflector_object.underscore string unless underscore_cache[string]
|
|
20
|
+
underscore_cache[string]
|
|
17
21
|
end
|
|
18
22
|
|
|
19
23
|
def pluralize(string)
|
|
20
|
-
inflector_object.pluralize string
|
|
24
|
+
pluralize_cache[string] = inflector_object.pluralize string unless pluralize_cache[string]
|
|
25
|
+
pluralize_cache[string]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def constantize(string)
|
|
29
|
+
constantize_cache[string] = Object.const_get string unless constantize_cache[string]
|
|
30
|
+
constantize_cache[string]
|
|
21
31
|
end
|
|
22
32
|
|
|
23
33
|
def collection?(object)
|
|
@@ -26,7 +36,7 @@ module Mutils
|
|
|
26
36
|
|
|
27
37
|
private
|
|
28
38
|
|
|
29
|
-
attr_accessor :inflector_object
|
|
39
|
+
attr_accessor :inflector_object, :pluralize_cache, :underscore_cache, :constantize_cache
|
|
30
40
|
end
|
|
31
41
|
end
|
|
32
42
|
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# module Mutils
|
|
4
|
+
module Mutils
|
|
5
|
+
module Lib
|
|
6
|
+
# ResultHash: Store result using this class.
|
|
7
|
+
class ResultHash
|
|
8
|
+
def initialize
|
|
9
|
+
self._hash = {}
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def []=(key, value)
|
|
13
|
+
_hash[key] = value
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def hash
|
|
17
|
+
_hash
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
attr_accessor :_hash
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -33,14 +33,6 @@ module Mutils
|
|
|
33
33
|
JSON.generate(as_json, options)
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
-
def to_xml(_options = {})
|
|
37
|
-
to_h.to_xml(root: class_name, skip_instruct: true, indent: 2)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def as_xml(_options = {})
|
|
41
|
-
to_xml
|
|
42
|
-
end
|
|
43
|
-
|
|
44
36
|
private
|
|
45
37
|
|
|
46
38
|
attr_writer :scope
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Module Mutils
|
|
4
|
+
module Mutils
|
|
5
|
+
# Module SerializationCore
|
|
6
|
+
module Serialization
|
|
7
|
+
# Module Methods
|
|
8
|
+
module Methods
|
|
9
|
+
# Module Attributes
|
|
10
|
+
module Attributes
|
|
11
|
+
def attributes(*attributes_list)
|
|
12
|
+
parse_attributes_methods(attributes_list, false)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def custom_methods(*attributes_list)
|
|
16
|
+
parse_attributes_methods(attributes_list, true)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def parse_attributes_methods(list, is_method)
|
|
20
|
+
self.attributes_to_serialize = {} if attributes_to_serialize.nil?
|
|
21
|
+
list&.each do |attr|
|
|
22
|
+
value = { method: is_method, always_include: true }
|
|
23
|
+
attributes_to_serialize[attr] = value
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def attribute(method_name, options = {}, &proc)
|
|
28
|
+
raise "if: should be a Proc object for attribute #{method_name}" if options[:if] && !options[:if].instance_of?(Proc)
|
|
29
|
+
|
|
30
|
+
if proc.instance_of? Proc
|
|
31
|
+
self.attributes_to_serialize_blocks = {} if attributes_to_serialize_blocks.nil?
|
|
32
|
+
options[:block] = proc
|
|
33
|
+
attributes_to_serialize_blocks[method_name] = options
|
|
34
|
+
else
|
|
35
|
+
add_single_attribute(method_name, options, false)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def custom_method(method_name, options = {})
|
|
40
|
+
add_single_attribute(method_name, options, true)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def add_single_attribute(method_name, options, is_method)
|
|
44
|
+
self.attributes_to_serialize = {} if attributes_to_serialize.nil?
|
|
45
|
+
always_include = options[:always_include].nil? ? false : options[:always_include]
|
|
46
|
+
value = { method: is_method, always_include: always_include, if: options[:if] }
|
|
47
|
+
attributes_to_serialize[method_name] = value
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Module Mutils
|
|
4
|
+
module Mutils
|
|
5
|
+
# Module SerializationCore
|
|
6
|
+
module Serialization
|
|
7
|
+
# Module Methods
|
|
8
|
+
module Methods
|
|
9
|
+
# Module Main
|
|
10
|
+
module Main
|
|
11
|
+
def name_tag(name_tag, root = nil)
|
|
12
|
+
self.serializer_name = name_tag
|
|
13
|
+
self.include_root = root
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def class_exists?(class_name)
|
|
17
|
+
klass = begin
|
|
18
|
+
Mutils::Lib::Helper.instance.constantize(class_name.to_s)
|
|
19
|
+
rescue StandardError
|
|
20
|
+
nil
|
|
21
|
+
end
|
|
22
|
+
klass && defined?(klass) && klass.is_a?(Class)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Module Mutils
|
|
4
|
+
module Mutils
|
|
5
|
+
# Module SerializationCore
|
|
6
|
+
module Serialization
|
|
7
|
+
# Module Methods
|
|
8
|
+
module Methods
|
|
9
|
+
# Module Relations
|
|
10
|
+
module Relations
|
|
11
|
+
def relationship(relationship_name, options = {})
|
|
12
|
+
raise "if: should be a Proc object for attribute #{relationship_name}" if options[:if] && !options[:if].instance_of?(Proc)
|
|
13
|
+
|
|
14
|
+
options = prepare_options(relationship_name, options, __callee__)
|
|
15
|
+
self.relationships = {} if relationships.nil?
|
|
16
|
+
relationships[relationship_name] = options
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
alias belongs_to relationship
|
|
20
|
+
alias has_many relationship
|
|
21
|
+
alias has_one relationship
|
|
22
|
+
|
|
23
|
+
def prepare_options(relationship_name, options, option_name)
|
|
24
|
+
class_name = options[:serializer]
|
|
25
|
+
if class_name.nil?
|
|
26
|
+
raise "Serializer is Required for belongs_to :#{relationship_name}." \
|
|
27
|
+
"\nDefine it like:\n#{option_name} :#{relationship_name}, " \
|
|
28
|
+
'serializer: SERIALIZER_CLASS'
|
|
29
|
+
end
|
|
30
|
+
raise "Serializer class not defined for relationship: #{relationship_name}" unless class_exists? class_name
|
|
31
|
+
|
|
32
|
+
options[:serializer] = class_name.to_s
|
|
33
|
+
options[:always_include] = options[:always_include].nil? ? false : options[:always_include]
|
|
34
|
+
options[:label] = Lib::Helper.instance.underscore options[:label] || relationship_name
|
|
35
|
+
options
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Module Mutils
|
|
4
|
+
module Mutils
|
|
5
|
+
module Serialization
|
|
6
|
+
# Module Results
|
|
7
|
+
module Results
|
|
8
|
+
# Module Attributes
|
|
9
|
+
module Attributes
|
|
10
|
+
def fetch_block_attributes(attributes, result_hash)
|
|
11
|
+
attributes&.each do |key, s_options|
|
|
12
|
+
result_hash[key] = s_options[:block].call(scope, options[:params] || {})
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def fetch_attributes(attributes, result_hash)
|
|
17
|
+
attributes&.each do |key, s_options|
|
|
18
|
+
check_if_included(s_options, key) && (result_hash[key] = s_options[:method] ? send(key) : scope.send(key))
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Module Mutils
|
|
4
|
+
module Mutils
|
|
5
|
+
module Serialization
|
|
6
|
+
# Module Results
|
|
7
|
+
module Results
|
|
8
|
+
# Module Attributes
|
|
9
|
+
module Main
|
|
10
|
+
def generate_hash
|
|
11
|
+
if scope
|
|
12
|
+
if scope_is_collection?
|
|
13
|
+
options[:child] = true
|
|
14
|
+
scope.map { |inner_scope| self.class.new(inner_scope, options).generate_hash }
|
|
15
|
+
else
|
|
16
|
+
hashed_result(Lib::ResultHash.new)
|
|
17
|
+
end
|
|
18
|
+
else
|
|
19
|
+
{}
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def hashed_result(result_hash)
|
|
24
|
+
fetch_block_attributes(self.class.attributes_to_serialize_blocks, result_hash)
|
|
25
|
+
fetch_attributes(self.class.attributes_to_serialize, result_hash)
|
|
26
|
+
hash_relationships(self.class.relationships, result_hash)
|
|
27
|
+
|
|
28
|
+
result_hash.hash
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def check_if_included(s_options, key)
|
|
32
|
+
return s_options[:if].call(scope, options[:params] || {}) unless s_options[:if].nil? || scope_is_collection?
|
|
33
|
+
|
|
34
|
+
s_options[:always_include] || options[:includes]&.include?(key)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def scope_is_collection?
|
|
38
|
+
Lib::Helper.instance.collection? scope
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def class_name
|
|
42
|
+
if scope_is_collection?
|
|
43
|
+
Lib::Helper.instance.pluralize(format_class_name(scope[0]))
|
|
44
|
+
else
|
|
45
|
+
format_class_name(scope)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def format_class_name(object)
|
|
50
|
+
if self.class.serializer_name&.length&.positive?
|
|
51
|
+
self.class.serializer_name
|
|
52
|
+
else
|
|
53
|
+
object.class.to_s.downcase
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Module Mutils
|
|
4
|
+
module Mutils
|
|
5
|
+
module Serialization
|
|
6
|
+
# Module Results
|
|
7
|
+
module Results
|
|
8
|
+
# Module Relations
|
|
9
|
+
module Relations
|
|
10
|
+
def hash_relationships(relationships_array, result_hash)
|
|
11
|
+
relationships = relationships_array&.compact
|
|
12
|
+
relationships&.each do |key, s_options|
|
|
13
|
+
object = scope.send(key)
|
|
14
|
+
name = s_options[:label]
|
|
15
|
+
Lib::Helper.instance.collection?(object) && (name = Lib::Helper.instance.pluralize(name))
|
|
16
|
+
name = name.to_sym
|
|
17
|
+
check_if_included(s_options, key) && (result_hash[name] = Lib::Helper.instance.constantize(s_options[:serializer]).new(object).to_h)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -1,90 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative 'methods/main'
|
|
4
|
+
require_relative 'methods/relations'
|
|
5
|
+
require_relative 'methods/attributes'
|
|
3
6
|
# Module Mutils
|
|
4
7
|
module Mutils
|
|
5
8
|
module Serialization
|
|
6
9
|
# Module SerializationCore
|
|
7
10
|
module SerializationMethods
|
|
8
11
|
def self.included(base)
|
|
9
|
-
base.extend
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
# Module ClassMethods
|
|
13
|
-
module ClassMethods
|
|
14
|
-
def name_tag(name_tag, root = nil)
|
|
15
|
-
self.serializer_name = name_tag
|
|
16
|
-
self.include_root = root
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def attributes(*attributes_list)
|
|
20
|
-
parse_attributes_methods(attributes_list, 'attributes')
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def custom_methods(*attributes_list)
|
|
24
|
-
parse_attributes_methods(attributes_list, 'method')
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def parse_attributes_methods(list, type)
|
|
28
|
-
self.attributes_to_serialize = {} if attributes_to_serialize.nil?
|
|
29
|
-
list&.each do |attr|
|
|
30
|
-
value = { method: type == 'method', always_include: true }
|
|
31
|
-
attributes_to_serialize[attr] = value
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def attribute(method_name, options = {}, &proc)
|
|
36
|
-
raise "if: should be a Proc object for attribute #{method_name}" if options[:if] && (options[:if].class.to_s != 'Proc')
|
|
37
|
-
|
|
38
|
-
if proc.class.to_s == 'Proc'
|
|
39
|
-
self.attributes_to_serialize_blocks = {} if attributes_to_serialize_blocks.nil?
|
|
40
|
-
options[:block] = proc
|
|
41
|
-
attributes_to_serialize_blocks[method_name] = options
|
|
42
|
-
else
|
|
43
|
-
add_single_attribute(method_name, options, 'attribute')
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def custom_method(method_name, options = {})
|
|
48
|
-
add_single_attribute(method_name, options, 'method')
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def add_single_attribute(method_name, options, type)
|
|
52
|
-
self.attributes_to_serialize = {} if attributes_to_serialize.nil?
|
|
53
|
-
always_include = options[:always_include].nil? ? false : options[:always_include]
|
|
54
|
-
value = { method: type == 'method', always_include: always_include, if: options[:if] }
|
|
55
|
-
attributes_to_serialize[method_name] = value
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def relationship(relationship_name, options = {})
|
|
59
|
-
options = prepare_options(relationship_name, options, __callee__)
|
|
60
|
-
self.relationships = {} if relationships.nil?
|
|
61
|
-
relationships[relationship_name] = options
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
alias belongs_to relationship
|
|
65
|
-
alias has_many relationship
|
|
66
|
-
alias has_one relationship
|
|
67
|
-
|
|
68
|
-
def prepare_options(relationship_name, options, option_name)
|
|
69
|
-
class_name = options[:serializer]
|
|
70
|
-
if class_name.nil?
|
|
71
|
-
raise "Serializer is Required for belongs_to :#{relationship_name}." \
|
|
72
|
-
"\nDefine it like:\n#{option_name} :#{relationship_name}, " \
|
|
73
|
-
'serializer: SERIALIZER_CLASS'
|
|
74
|
-
end
|
|
75
|
-
raise "Serializer class not defined for relationship: #{relationship_name}" unless class_exists? class_name
|
|
76
|
-
raise "if: should be a Proc object for attribute #{relationship_name}" if options[:if] && (options[:if].class.to_s != 'Proc')
|
|
77
|
-
|
|
78
|
-
options[:serializer] = Object.const_get class_name.to_s
|
|
79
|
-
options[:option_name] = option_name
|
|
80
|
-
options[:label] = options[:label]
|
|
81
|
-
options
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def class_exists?(class_name)
|
|
85
|
-
klass = Object.const_get class_name.to_s rescue nil
|
|
86
|
-
klass && defined?(klass) && klass.is_a?(Class)
|
|
87
|
-
end
|
|
12
|
+
base.extend Methods::Main
|
|
13
|
+
base.extend Methods::Attributes
|
|
14
|
+
base.extend Methods::Relations
|
|
88
15
|
end
|
|
89
16
|
end
|
|
90
17
|
end
|
|
@@ -1,87 +1,16 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative 'results/main'
|
|
4
|
+
require_relative 'results/attributes'
|
|
5
|
+
require_relative 'results/relations'
|
|
3
6
|
# Module Mutils
|
|
4
7
|
module Mutils
|
|
5
8
|
module Serialization
|
|
6
9
|
# Module SerializationResults
|
|
7
10
|
module SerializationResults
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
options[:child] = true
|
|
12
|
-
scope.map { |inner_scope| self.class.new(inner_scope, options).generate_hash }
|
|
13
|
-
else
|
|
14
|
-
hashed_result
|
|
15
|
-
end
|
|
16
|
-
else
|
|
17
|
-
{}
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def hashed_result
|
|
22
|
-
[fetch_block_attributes(self.class.attributes_to_serialize_blocks),
|
|
23
|
-
fetch_attributes(self.class.attributes_to_serialize),
|
|
24
|
-
hash_relationships(self.class.relationships)].reduce(&:merge)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def fetch_block_attributes(attributes)
|
|
28
|
-
hash = {}
|
|
29
|
-
attributes&.keys&.each do |key|
|
|
30
|
-
hash[key] = attributes[key][:block].call(scope, options[:params])
|
|
31
|
-
end
|
|
32
|
-
hash
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def fetch_attributes(attributes)
|
|
36
|
-
hash = {}
|
|
37
|
-
attributes&.keys&.each do |key|
|
|
38
|
-
check_if_included(attributes, key) && (hash[key] = attributes[key][:method] ? send(key) : scope.send(key))
|
|
39
|
-
end
|
|
40
|
-
hash
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def hash_relationships(relationships_array)
|
|
44
|
-
relationships = relationships_array&.compact
|
|
45
|
-
hash = {}
|
|
46
|
-
relationships&.keys&.each do |key|
|
|
47
|
-
object = scope.send(key)
|
|
48
|
-
name = key
|
|
49
|
-
if (label = relationships[key][:label])
|
|
50
|
-
name = Lib::Helper.instance.underscore label
|
|
51
|
-
Lib::Helper.instance.collection?(object) && (name = Lib::Helper.instance.pluralize(name))
|
|
52
|
-
name = name.to_sym
|
|
53
|
-
end
|
|
54
|
-
check_if_included(relationships, key) && (hash[name] = relationships[key][:serializer].new(object).to_h)
|
|
55
|
-
end
|
|
56
|
-
hash
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def check_if_included(relationships, key)
|
|
60
|
-
return relationships[key][:if].call(scope) unless relationships[key][:if].nil? || scope_is_collection?
|
|
61
|
-
|
|
62
|
-
always_include = relationships[key][:always_include] == true
|
|
63
|
-
always_include || options[:includes]&.include?(key)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def scope_is_collection?
|
|
67
|
-
Lib::Helper.instance.collection? scope
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def class_name
|
|
71
|
-
if scope_is_collection?
|
|
72
|
-
Lib::Helper.name.pluralize(format_class_name(scope[0]))
|
|
73
|
-
else
|
|
74
|
-
format_class_name(scope)
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def format_class_name(object)
|
|
79
|
-
if self.class.serializer_name&.length&.positive?
|
|
80
|
-
self.class.serializer_name
|
|
81
|
-
else
|
|
82
|
-
object.class.to_s.downcase
|
|
83
|
-
end
|
|
84
|
-
end
|
|
11
|
+
include Mutils::Serialization::Results::Main
|
|
12
|
+
include Mutils::Serialization::Results::Attributes
|
|
13
|
+
include Mutils::Serialization::Results::Relations
|
|
85
14
|
end
|
|
86
15
|
end
|
|
87
16
|
end
|