eac_ruby_utils 0.96.0 → 0.96.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 536eb071e735c3f9aeaa4a1282b06dd1d119c740dc6a04408dead8ab4573d534
4
- data.tar.gz: f6ff16c4ee2e2547a1d29f30006f5a533cef687b6e583746e88c4a35ad2c67e1
3
+ metadata.gz: d4035271ba1a01e74ba0ca6f13d95db76783f67d50d002df5c54c0668a5ec160
4
+ data.tar.gz: ab9d27a5d400c1294c0b0fc245f904ac48fb039085f3366a3c69159045e1ebb7
5
5
  SHA512:
6
- metadata.gz: 04bddf5187e0cc95d70a24f2e1df9a679201b3eae3f5b6bef1bdba45f44411ce19ee11c0907c39e34e29d35fed999a42932ce72a6de6478514073d1319a063e4
7
- data.tar.gz: 4911aaf282906bf1da118dc4f0a3704cc5072fee08420bf68a45ef33d3e24e0e092e722913ec55b3ab424556a765283b7e377a1ae690ba6dab8f18a45e7e1594
6
+ metadata.gz: '0830e227136ef0fe56b0ea9e87cd9dfd1c6f5e6e69f6b88f3b51c736ea4305647c3a4fa138417e09bf096d7ba0345aeff8f634fb592f740ee193b68422876189'
7
+ data.tar.gz: c989244e994c84f953beda82ed0999b00e91a45b355eb148ce4830a5b85bd43d813d9e886ce70f792e5a5f4e4d833928592242615be333042b096cbb59aff37b
@@ -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 'active_support/inflector'
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.96.0'
4
+ VERSION = '0.96.1'
5
5
  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.96.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-25 00:00:00.000000000 Z
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