eac_ruby_utils 0.95.2 → 0.96.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4035271ba1a01e74ba0ca6f13d95db76783f67d50d002df5c54c0668a5ec160
|
4
|
+
data.tar.gz: ab9d27a5d400c1294c0b0fc245f904ac48fb039085f3366a3c69159045e1ebb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0830e227136ef0fe56b0ea9e87cd9dfd1c6f5e6e69f6b88f3b51c736ea4305647c3a4fa138417e09bf096d7ba0345aeff8f634fb592f740ee193b68422876189'
|
7
|
+
data.tar.gz: c989244e994c84f953beda82ed0999b00e91a45b355eb148ce4830a5b85bd43d813d9e886ce70f792e5a5f4e4d833928592242615be333042b096cbb59aff37b
|
@@ -8,13 +8,26 @@ module EacRubyUtils
|
|
8
8
|
module Immutable
|
9
9
|
class ArrayAccessor < ::EacRubyUtils::Immutable::BaseAccessor
|
10
10
|
def apply(klass)
|
11
|
+
apply_singular(klass)
|
12
|
+
apply_plural(klass)
|
13
|
+
end
|
14
|
+
|
15
|
+
def apply_plural(klass)
|
11
16
|
accessor = self
|
12
|
-
klass.send(:define_method, name) do |
|
13
|
-
|
17
|
+
klass.send(:define_method, ::ActiveSupport::Inflector.pluralize(name)) do |*args|
|
18
|
+
case args.count
|
19
|
+
when 0 then next accessor.immutable_value_get(self)
|
20
|
+
when 1 then next accessor.immutable_value_set(self, args.first)
|
21
|
+
else
|
22
|
+
raise ::ArgumentError, "wrong number of arguments (given #{args.count}, expected 0..1)"
|
23
|
+
end
|
14
24
|
end
|
25
|
+
end
|
15
26
|
|
16
|
-
|
17
|
-
|
27
|
+
def apply_singular(klass)
|
28
|
+
accessor = self
|
29
|
+
klass.send(:define_method, name) do |value|
|
30
|
+
accessor.immutable_value_push(self, value)
|
18
31
|
end
|
19
32
|
end
|
20
33
|
|
@@ -22,11 +35,15 @@ module EacRubyUtils
|
|
22
35
|
super || []
|
23
36
|
end
|
24
37
|
|
25
|
-
def
|
38
|
+
def immutable_value_push(object, value)
|
26
39
|
duplicate_object(object) do |old_value|
|
27
40
|
(old_value || []) + [value]
|
28
41
|
end
|
29
42
|
end
|
43
|
+
|
44
|
+
def immutable_value_set(object, value)
|
45
|
+
duplicate_object(object) { |_old_value| value }
|
46
|
+
end
|
30
47
|
end
|
31
48
|
end
|
32
49
|
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/listable'
|
4
|
+
require 'eac_ruby_utils/require_sub/sub_file'
|
5
|
+
|
6
|
+
module EacRubyUtils
|
7
|
+
module RequireSub
|
8
|
+
class Base
|
9
|
+
INCLUDE_MODULES_MAP = {
|
10
|
+
nil => nil,
|
11
|
+
false => nil,
|
12
|
+
true => :include,
|
13
|
+
include: :include,
|
14
|
+
prepend: :prepend
|
15
|
+
}.freeze
|
16
|
+
|
17
|
+
include ::EacRubyUtils::Listable
|
18
|
+
lists.add_symbol :option, :base, :include_modules, :require_dependency
|
19
|
+
|
20
|
+
attr_reader :file, :options
|
21
|
+
|
22
|
+
def initialize(file, options = {})
|
23
|
+
@file = file
|
24
|
+
@options = self.class.lists.option.hash_keys_validate!(options)
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return [Boolean]
|
28
|
+
def active_support_require?
|
29
|
+
options[OPTION_REQUIRE_DEPENDENCY] ? true : false
|
30
|
+
end
|
31
|
+
|
32
|
+
def apply
|
33
|
+
require_sub_files
|
34
|
+
include_modules
|
35
|
+
end
|
36
|
+
|
37
|
+
def base
|
38
|
+
options[OPTION_BASE] || raise('Option :base not setted')
|
39
|
+
end
|
40
|
+
|
41
|
+
def base?
|
42
|
+
options[OPTION_BASE] ? true : false
|
43
|
+
end
|
44
|
+
|
45
|
+
def include_modules
|
46
|
+
sub_files.each(&:include_module)
|
47
|
+
end
|
48
|
+
|
49
|
+
def include_or_prepend_method
|
50
|
+
return INCLUDE_MODULES_MAP.fetch(options[OPTION_INCLUDE_MODULES]) if
|
51
|
+
INCLUDE_MODULES_MAP.key?(options[OPTION_INCLUDE_MODULES])
|
52
|
+
|
53
|
+
raise ::ArgumentError, "Invalid value for 'options[OPTION_INCLUDE_MODULES]':" \
|
54
|
+
" \"#{options[OPTION_INCLUDE_MODULES]}\""
|
55
|
+
end
|
56
|
+
|
57
|
+
def require_sub_files
|
58
|
+
sub_files.each(&:require_file)
|
59
|
+
end
|
60
|
+
|
61
|
+
def sub_files
|
62
|
+
@sub_files ||= Dir["#{File.dirname(file)}/#{::File.basename(file, '.*')}/*.rb"].sort
|
63
|
+
.map { |path| ::EacRubyUtils::RequireSub::SubFile.new(self, path) }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/dependencies'
|
4
|
+
require 'active_support/inflector'
|
5
|
+
|
6
|
+
module EacRubyUtils
|
7
|
+
module RequireSub
|
8
|
+
class SubFile
|
9
|
+
attr_reader :owner, :path
|
10
|
+
|
11
|
+
def initialize(owner, path)
|
12
|
+
@owner = owner
|
13
|
+
@path = path
|
14
|
+
end
|
15
|
+
|
16
|
+
def base_constant
|
17
|
+
return nil unless owner.base?
|
18
|
+
|
19
|
+
owner.base.const_get(constant_name)
|
20
|
+
rescue ::NameError
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def constant_name
|
25
|
+
::ActiveSupport::Inflector.camelize(::File.basename(path, '.rb'))
|
26
|
+
end
|
27
|
+
|
28
|
+
def include_module
|
29
|
+
return unless module?
|
30
|
+
|
31
|
+
owner.include_or_prepend_method.if_present do |v|
|
32
|
+
owner.base.send(v, base_constant)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def module?
|
37
|
+
base_constant.is_a?(::Module) && !base_constant.is_a?(::Class)
|
38
|
+
end
|
39
|
+
|
40
|
+
def require_file
|
41
|
+
active_support_require || autoload_require || kernel_require
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def active_support_require
|
47
|
+
return false unless owner.active_support_require?
|
48
|
+
|
49
|
+
::Kernel.require_dependency(path)
|
50
|
+
true
|
51
|
+
end
|
52
|
+
|
53
|
+
def autoload_require
|
54
|
+
return false unless owner.base?
|
55
|
+
|
56
|
+
basename = ::File.basename(path, '.*')
|
57
|
+
return false if basename.start_with?('_')
|
58
|
+
|
59
|
+
owner.base.autoload ::ActiveSupport::Inflector.camelize(basename), path
|
60
|
+
true
|
61
|
+
end
|
62
|
+
|
63
|
+
def kernel_require
|
64
|
+
::Kernel.require(path)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -1,134 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'active_support/dependencies'
|
5
|
-
require 'eac_ruby_utils/listable'
|
3
|
+
require 'eac_ruby_utils/require_sub/base'
|
6
4
|
|
7
5
|
module EacRubyUtils
|
8
6
|
class << self
|
9
7
|
def require_sub(file, options = {})
|
10
|
-
::EacRubyUtils::RequireSub.new(file, options).apply
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class RequireSub
|
15
|
-
INCLUDE_MODULES_MAP = {
|
16
|
-
nil => nil,
|
17
|
-
false => nil,
|
18
|
-
true => :include,
|
19
|
-
include: :include,
|
20
|
-
prepend: :prepend
|
21
|
-
}.freeze
|
22
|
-
|
23
|
-
include ::EacRubyUtils::Listable
|
24
|
-
lists.add_symbol :option, :base, :include_modules, :require_dependency
|
25
|
-
|
26
|
-
attr_reader :file, :options
|
27
|
-
|
28
|
-
def initialize(file, options = {})
|
29
|
-
@file = file
|
30
|
-
@options = self.class.lists.option.hash_keys_validate!(options)
|
31
|
-
end
|
32
|
-
|
33
|
-
def apply
|
34
|
-
require_sub_files
|
35
|
-
include_modules
|
36
|
-
end
|
37
|
-
|
38
|
-
def base
|
39
|
-
options[OPTION_BASE] || raise('Option :base not setted')
|
40
|
-
end
|
41
|
-
|
42
|
-
def base?
|
43
|
-
options[OPTION_BASE] ? true : false
|
44
|
-
end
|
45
|
-
|
46
|
-
def include_modules
|
47
|
-
sub_files.each(&:include_module)
|
48
|
-
end
|
49
|
-
|
50
|
-
def include_or_prepend_method
|
51
|
-
return INCLUDE_MODULES_MAP.fetch(options[OPTION_INCLUDE_MODULES]) if
|
52
|
-
INCLUDE_MODULES_MAP.key?(options[OPTION_INCLUDE_MODULES])
|
53
|
-
|
54
|
-
raise ::ArgumentError, "Invalid value for 'options[OPTION_INCLUDE_MODULES]':" \
|
55
|
-
" \"#{options[OPTION_INCLUDE_MODULES]}\""
|
56
|
-
end
|
57
|
-
|
58
|
-
def require_sub_files
|
59
|
-
sub_files.each(&:require_file)
|
60
|
-
end
|
61
|
-
|
62
|
-
def sub_files
|
63
|
-
@sub_files ||= Dir["#{File.dirname(file)}/#{::File.basename(file, '.*')}/*.rb"].sort
|
64
|
-
.map { |path| SubFile.new(self, path) }
|
65
|
-
end
|
66
|
-
|
67
|
-
class SubFile
|
68
|
-
attr_reader :owner, :path
|
69
|
-
|
70
|
-
def initialize(owner, path)
|
71
|
-
@owner = owner
|
72
|
-
@path = path
|
73
|
-
end
|
74
|
-
|
75
|
-
def base_constant
|
76
|
-
return nil unless owner.base?
|
77
|
-
|
78
|
-
owner.base.const_get(constant_name)
|
79
|
-
rescue ::NameError
|
80
|
-
nil
|
81
|
-
end
|
82
|
-
|
83
|
-
def constant_name
|
84
|
-
::ActiveSupport::Inflector.camelize(::File.basename(path, '.rb'))
|
85
|
-
end
|
86
|
-
|
87
|
-
def include_module
|
88
|
-
return unless module?
|
89
|
-
|
90
|
-
owner.include_or_prepend_method.if_present do |v|
|
91
|
-
owner.base.send(v, base_constant)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
def include_or_prepend_method
|
96
|
-
return :include if owner.options[OPTION_INCLUDE_MODULES]
|
97
|
-
return :prepend if owner.options[OPTION_PREPEND_MODULES]
|
98
|
-
|
99
|
-
nil
|
100
|
-
end
|
101
|
-
|
102
|
-
def module?
|
103
|
-
base_constant.is_a?(::Module) && !base_constant.is_a?(::Class)
|
104
|
-
end
|
105
|
-
|
106
|
-
def require_file
|
107
|
-
active_support_require || autoload_require || kernel_require
|
108
|
-
end
|
109
|
-
|
110
|
-
private
|
111
|
-
|
112
|
-
def active_support_require
|
113
|
-
return false unless owner.options[OPTION_REQUIRE_DEPENDENCY]
|
114
|
-
|
115
|
-
::Kernel.require_dependency(path)
|
116
|
-
true
|
117
|
-
end
|
118
|
-
|
119
|
-
def autoload_require
|
120
|
-
return false unless owner.base?
|
121
|
-
|
122
|
-
basename = ::File.basename(path, '.*')
|
123
|
-
return false if basename.start_with?('_')
|
124
|
-
|
125
|
-
owner.base.autoload ::ActiveSupport::Inflector.camelize(basename), path
|
126
|
-
true
|
127
|
-
end
|
128
|
-
|
129
|
-
def kernel_require
|
130
|
-
::Kernel.require(path)
|
131
|
-
end
|
8
|
+
::EacRubyUtils::RequireSub::Base.new(file, options).apply
|
132
9
|
end
|
133
10
|
end
|
134
11
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eac_ruby_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.96.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Esquilo Azul Company
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-07-
|
11
|
+
date: 2022-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -241,6 +241,8 @@ files:
|
|
241
241
|
- lib/eac_ruby_utils/recursive_builder.rb
|
242
242
|
- lib/eac_ruby_utils/regexp_parser.rb
|
243
243
|
- lib/eac_ruby_utils/require_sub.rb
|
244
|
+
- lib/eac_ruby_utils/require_sub/base.rb
|
245
|
+
- lib/eac_ruby_utils/require_sub/sub_file.rb
|
244
246
|
- lib/eac_ruby_utils/rspec.rb
|
245
247
|
- lib/eac_ruby_utils/rspec/default_setup.rb
|
246
248
|
- lib/eac_ruby_utils/rspec/setup.rb
|