eac_ruby_utils 0.96.0 → 0.98.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/eac_ruby_utils/patches/addressable/uri/query_value.rb +37 -0
- data/lib/eac_ruby_utils/patches/addressable/uri.rb +4 -0
- data/lib/eac_ruby_utils/patches/addressable.rb +4 -0
- data/lib/eac_ruby_utils/regexp_parser.rb +5 -0
- data/lib/eac_ruby_utils/require_sub/base.rb +67 -0
- data/lib/eac_ruby_utils/require_sub/sub_file.rb +68 -0
- data/lib/eac_ruby_utils/require_sub.rb +2 -125
- data/lib/eac_ruby_utils/version.rb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e589ad673e489c92596bc3ad46ec06db307af584835cae664a96b163a9e1534
|
4
|
+
data.tar.gz: 6a8f0a202d5fd79decc0a3e416b4b83a559f36ff2258510b2a92db2d5ea8c653
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0184ca1df801cbbc7bdd241e15e628dbc42fa692695500ce0b77c11384d131712587834d36ddc6399926c3513548c6d59d1be53d9777306d12714f9b2d63d7af'
|
7
|
+
data.tar.gz: 36991e903d0f00b8cac236477e8775915cb03dfb2a521308fba707dce3142b4ca0b305b4da34c04c9932de26ae7074ba22ce510b493621b97af815732ec7c678
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'addressable'
|
4
|
+
|
5
|
+
module Addressable
|
6
|
+
class URI
|
7
|
+
# @return [ActiveSupport:HashWithIndifferentAccess]
|
8
|
+
def hash_query_values
|
9
|
+
(query_values || {}).with_indifferent_access
|
10
|
+
end
|
11
|
+
|
12
|
+
def query_value(*args)
|
13
|
+
if args.count == 1
|
14
|
+
query_value_get(*args)
|
15
|
+
elsif args.count == 2
|
16
|
+
query_value_set(*args)
|
17
|
+
else
|
18
|
+
raise ::ArgumentError, "#{object.class}.#{__method__}: wrong number of arguments" \
|
19
|
+
" (given #{args.count}, expected 1..2)"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def query_value_get(name)
|
26
|
+
hash_query_values[name]
|
27
|
+
end
|
28
|
+
|
29
|
+
def query_value_set(name, value)
|
30
|
+
new_query_values = hash_query_values
|
31
|
+
new_query_values[name] = value
|
32
|
+
self.query_values = new_query_values
|
33
|
+
|
34
|
+
self
|
35
|
+
end
|
36
|
+
end
|
37
|
+
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.98.0
|
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-
|
11
|
+
date: 2022-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -182,6 +182,9 @@ files:
|
|
182
182
|
- lib/eac_ruby_utils/options_consumer.rb
|
183
183
|
- lib/eac_ruby_utils/patch.rb
|
184
184
|
- lib/eac_ruby_utils/patches.rb
|
185
|
+
- lib/eac_ruby_utils/patches/addressable.rb
|
186
|
+
- lib/eac_ruby_utils/patches/addressable/uri.rb
|
187
|
+
- lib/eac_ruby_utils/patches/addressable/uri/query_value.rb
|
185
188
|
- lib/eac_ruby_utils/patches/class.rb
|
186
189
|
- lib/eac_ruby_utils/patches/class/abstract.rb
|
187
190
|
- lib/eac_ruby_utils/patches/class/common_constructor.rb
|
@@ -241,6 +244,8 @@ files:
|
|
241
244
|
- lib/eac_ruby_utils/recursive_builder.rb
|
242
245
|
- lib/eac_ruby_utils/regexp_parser.rb
|
243
246
|
- lib/eac_ruby_utils/require_sub.rb
|
247
|
+
- lib/eac_ruby_utils/require_sub/base.rb
|
248
|
+
- lib/eac_ruby_utils/require_sub/sub_file.rb
|
244
249
|
- lib/eac_ruby_utils/rspec.rb
|
245
250
|
- lib/eac_ruby_utils/rspec/default_setup.rb
|
246
251
|
- lib/eac_ruby_utils/rspec/setup.rb
|