eac_ruby_utils 0.33.1 → 0.34.0

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: b15ce47fc0a4be7f0d4d5c508e7460447818bcc4eef4f1b49d70c21475320091
4
- data.tar.gz: 904f3e7fddda7113e1b70decadd20e9d1fd0e36c5a2f5467067a76abc1680ee1
3
+ metadata.gz: 4a1ec180f3a7aef3fae244443ddd7d9650402e4a7f26757068ee318dce2e9cc9
4
+ data.tar.gz: bf7cb26680fb44edcf31b169dd8014dc0bb7f2e7ccbfee664a480751a11fc967
5
5
  SHA512:
6
- metadata.gz: 24b859d02cbb17c2a87f89fecfac6d066cc3446516ecb34dc92d56bbc403a3969229e59622e0c654daf816585b539d14bed37400a072cd63fdf67160804e9d42
7
- data.tar.gz: b02dc4a1d20787d3cbc0de8a0831d6c0cda42a5f2a6c7af3ce6fb7b6e85e65fd93ef9253d889297c034f8452e867735a8b9a4e5f1cbcd8c49028f4ee26f1a201
6
+ metadata.gz: 8c97935d7790e791ffa864420a353abe203751af236dd494a91729a27f7caaaf796430025a3a11e3e32023e8330570cd2bb1c328be2702caaaa7110a62b9a8cf
7
+ data.tar.gz: acbb32cb1398e8fb4b36eaf367cf222a7de7d92f2afbca5dd3de3747d77a2e2c9b7ea4ad72e4852e6e79bd69dd336e6a46cd32a67717cf0be00ef60c6fc45866
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/concern'
4
+ require 'eac_ruby_utils/simple_cache'
5
+ require 'eac_ruby_utils/patches/object/if_present'
6
+
7
+ module EacRubyUtils
8
+ class CommonConcern
9
+ CLASS_METHODS_MODULE_NAME = 'ClassMethods'
10
+ INSTANCE_METHODS_MODULE_NAME = 'InstanceMethods'
11
+
12
+ attr_reader :after_callback
13
+
14
+ def initialize(&after_callback)
15
+ @after_callback = after_callback
16
+ end
17
+
18
+ def setup(a_module)
19
+ Setup.new(self, a_module).run
20
+ end
21
+
22
+ class Setup
23
+ include ::EacRubyUtils::SimpleCache
24
+ attr_reader :a_module, :common_constructor
25
+
26
+ def initialize(common_constructor, a_module)
27
+ @common_constructor = common_constructor
28
+ @a_module = a_module
29
+ end
30
+
31
+ def run
32
+ setup = self
33
+ a_module.extend(::ActiveSupport::Concern)
34
+ a_module.included do
35
+ %w[class_methods instance_methods after_callback].each do |suffix|
36
+ setup.send("setup_#{suffix}", self)
37
+ end
38
+ end
39
+ end
40
+
41
+ def setup_class_methods(base)
42
+ class_methods_module.if_present { |v| base.extend v }
43
+ end
44
+
45
+ def setup_instance_methods(base)
46
+ instance_methods_module.if_present { |v| base.include v }
47
+ end
48
+
49
+ def setup_after_callback(base)
50
+ common_constructor.after_callback.if_present do |v|
51
+ base.instance_eval(&v)
52
+ end
53
+ end
54
+
55
+ def class_methods_module_uncached
56
+ a_module.const_get(CLASS_METHODS_MODULE_NAME)
57
+ rescue NameError
58
+ nil
59
+ end
60
+
61
+ def instance_methods_module_uncached
62
+ a_module.const_get(INSTANCE_METHODS_MODULE_NAME)
63
+ rescue NameError
64
+ nil
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/common_concern'
4
+ require 'eac_ruby_utils/console/speaker'
5
+
6
+ class Module
7
+ def common_concern(&after_callback)
8
+ ::EacRubyUtils::CommonConcern.new(&after_callback).setup(self)
9
+ end
10
+ end
@@ -3,7 +3,7 @@
3
3
  require 'eac_ruby_utils/require_sub'
4
4
 
5
5
  class Module
6
- def require_sub(file_path)
7
- ::EacRubyUtils.require_sub(file_path)
6
+ def require_sub(file_path, options = {})
7
+ ::EacRubyUtils.require_sub(file_path, { base: self }.merge(options))
8
8
  end
9
9
  end
@@ -2,7 +2,45 @@
2
2
 
3
3
  module EacRubyUtils
4
4
  class << self
5
- def require_sub(file)
5
+ def require_sub(file, options = {})
6
+ ::EacRubyUtils::RequireSub.new(file, options).apply
7
+ end
8
+ end
9
+
10
+ class RequireSub
11
+ BASE_OPTION_KEY = :base
12
+ INCLUDE_MODULES_OPTION_KEY = :include_modules
13
+
14
+ attr_reader :file, :options
15
+
16
+ def initialize(file, options = {})
17
+ @file = file
18
+ @options = options
19
+ end
20
+
21
+ def apply
22
+ require_sub_files
23
+ include_modules
24
+ end
25
+
26
+ private
27
+
28
+ def include_modules
29
+ return unless options[INCLUDE_MODULES_OPTION_KEY]
30
+
31
+ base.constants.each do |constant_name|
32
+ constant = base.const_get(constant_name)
33
+ next unless constant.is_a?(::Module) && !constant.is_a?(::Class)
34
+
35
+ base.include(constant)
36
+ end
37
+ end
38
+
39
+ def base
40
+ options[BASE_OPTION_KEY] || raise('Option :base not setted')
41
+ end
42
+
43
+ def require_sub_files
6
44
  Dir["#{File.dirname(file)}/#{::File.basename(file, '.*')}/*.rb"].sort.each do |path|
7
45
  require path
8
46
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.33.1'
4
+ VERSION = '0.34.0'
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.33.1
4
+ version: 0.34.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: 2020-05-29 00:00:00.000000000 Z
11
+ date: 2020-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -110,6 +110,7 @@ files:
110
110
  - lib/eac_ruby_utils.rb
111
111
  - lib/eac_ruby_utils/arguments_consumer.rb
112
112
  - lib/eac_ruby_utils/by_reference.rb
113
+ - lib/eac_ruby_utils/common_concern.rb
113
114
  - lib/eac_ruby_utils/common_constructor.rb
114
115
  - lib/eac_ruby_utils/configs.rb
115
116
  - lib/eac_ruby_utils/configs/file.rb
@@ -167,6 +168,7 @@ files:
167
168
  - lib/eac_ruby_utils/patches/hash/options_consumer.rb
168
169
  - lib/eac_ruby_utils/patches/hash/sym_keys_hash.rb
169
170
  - lib/eac_ruby_utils/patches/module.rb
171
+ - lib/eac_ruby_utils/patches/module/common_concern.rb
170
172
  - lib/eac_ruby_utils/patches/module/console_speaker.rb
171
173
  - lib/eac_ruby_utils/patches/module/listable.rb
172
174
  - lib/eac_ruby_utils/patches/module/patch.rb