eac_ruby_utils 0.64.0 → 0.69.0
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/lib/eac_ruby_utils/context.rb +31 -0
- data/lib/eac_ruby_utils/contextualizable.rb +12 -7
- data/lib/eac_ruby_utils/patches/module/context.rb +11 -0
- data/lib/eac_ruby_utils/patches/module/speaker.rb +9 -0
- data/lib/eac_ruby_utils/patches/pathname/parent_n.rb +11 -0
- data/lib/eac_ruby_utils/simple_cache.rb +10 -2
- data/lib/eac_ruby_utils/speaker.rb +16 -0
- data/lib/eac_ruby_utils/speaker/receiver.rb +57 -0
- data/lib/eac_ruby_utils/speaker/sender.rb +32 -0
- data/lib/eac_ruby_utils/version.rb +1 -1
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fab6e5db312ff7ad93ceadf6412b41ecb725d5ad8ea13c0b0f4f350b6d2dfa0
|
4
|
+
data.tar.gz: 1a3a81dfa1baaac26a79bcd25f2b6559555445b7f1075a00d54d7ed78fd999c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e776c88a80777227d29e2055e2f06e865d849486aa8d7489f56156e986030dd0bf6a9c261c01a3ec7a1775581780f2ad201e4c26a9b68fc4b24c6eef0b01f090
|
7
|
+
data.tar.gz: ca955067e64bd91a42d606e6d55c0bb3655ee140b18db5452276972f4ac1dcbceb5aacbfedf6f8638f8f246e8d1b9b0a6f56c639415ce91510cd67754b9f8848
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacRubyUtils
|
4
|
+
class Context
|
5
|
+
def current
|
6
|
+
optional_current || raise('No elements in context')
|
7
|
+
end
|
8
|
+
|
9
|
+
def optional_current
|
10
|
+
stack.last
|
11
|
+
end
|
12
|
+
|
13
|
+
delegate :pop, to: :stack
|
14
|
+
delegate :push, to: :stack
|
15
|
+
|
16
|
+
def on(obj)
|
17
|
+
push(obj)
|
18
|
+
begin
|
19
|
+
yield
|
20
|
+
ensure
|
21
|
+
pop
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def stack
|
28
|
+
@stack ||= []
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -1,16 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'eac_ruby_utils/context'
|
4
|
+
|
3
5
|
module EacRubyUtils
|
4
|
-
# Provides the method context which search and call a method in self and ancestor objects.
|
5
6
|
module Contextualizable
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
common_concern
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def context
|
11
|
+
@context ||= ::EacRubyUtils::Context.new
|
12
|
+
end
|
13
|
+
end
|
10
14
|
|
11
|
-
|
15
|
+
module InstanceMethods
|
16
|
+
def context
|
17
|
+
self.class.context
|
12
18
|
end
|
13
|
-
raise "Context method \"#{method}\" not found for #{self.class}"
|
14
19
|
end
|
15
20
|
end
|
16
21
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/patch'
|
4
|
+
require 'eac_ruby_utils/contextualizable'
|
5
|
+
|
6
|
+
class Module
|
7
|
+
# Patches module with [EacRubyUtils::Contextualizable].
|
8
|
+
def enable_context
|
9
|
+
::EacRubyUtils.patch(self, ::EacRubyUtils::Contextualizable)
|
10
|
+
end
|
11
|
+
end
|
@@ -3,11 +3,19 @@
|
|
3
3
|
module EacRubyUtils
|
4
4
|
module SimpleCache
|
5
5
|
UNCACHED_METHOD_NAME_SUFFIX = '_uncached'
|
6
|
-
UNCACHED_METHOD_PATTERN =
|
6
|
+
UNCACHED_METHOD_PATTERN = /
|
7
|
+
\A(\s+)_#{::Regexp.quote(UNCACHED_METHOD_NAME_SUFFIX)}([\!\?]?)\z
|
8
|
+
/x.freeze
|
7
9
|
|
8
10
|
class << self
|
9
11
|
def uncached_method_name(method_name)
|
10
|
-
|
12
|
+
method_name = method_name.to_s
|
13
|
+
end_mark = nil
|
14
|
+
if %w[! ?].any? { |mark| method_name.end_with?(mark) }
|
15
|
+
end_mark = method_name[-1]
|
16
|
+
method_name = method_name[0..-2]
|
17
|
+
end
|
18
|
+
"#{method_name}#{UNCACHED_METHOD_NAME_SUFFIX}#{end_mark}"
|
11
19
|
end
|
12
20
|
end
|
13
21
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/contextualizable'
|
4
|
+
|
5
|
+
module EacRubyUtils
|
6
|
+
module Speaker
|
7
|
+
include ::EacRubyUtils::Contextualizable
|
8
|
+
|
9
|
+
class << self
|
10
|
+
# @return [EacRubyUtils::Speaker::Receiver]
|
11
|
+
def current_receiver
|
12
|
+
context.current
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/abstract_methods'
|
4
|
+
|
5
|
+
module EacRubyUtils
|
6
|
+
module Speaker
|
7
|
+
module Receiver
|
8
|
+
extend ::EacRubyUtils::AbstractMethods
|
9
|
+
|
10
|
+
def error(_string)
|
11
|
+
raise_abstract_method(__FILE__)
|
12
|
+
end
|
13
|
+
|
14
|
+
def fatal_error(string)
|
15
|
+
error(string)
|
16
|
+
::Kernel.exit 1 # rubocop:disable Rails/Exit
|
17
|
+
end
|
18
|
+
|
19
|
+
# @see EacRubyUtils::Speaker::Sender.input
|
20
|
+
def input(_question, _options = {})
|
21
|
+
raise_abstract_method(__FILE__)
|
22
|
+
end
|
23
|
+
|
24
|
+
def info(_string)
|
25
|
+
raise_abstract_method(__FILE__)
|
26
|
+
end
|
27
|
+
|
28
|
+
def infom(_string)
|
29
|
+
raise_abstract_method(__FILE__)
|
30
|
+
end
|
31
|
+
|
32
|
+
def infov(*_args)
|
33
|
+
raise_abstract_method(__FILE__)
|
34
|
+
end
|
35
|
+
|
36
|
+
def out(_string = '')
|
37
|
+
raise_abstract_method(__FILE__)
|
38
|
+
end
|
39
|
+
|
40
|
+
def puts(_string = '')
|
41
|
+
raise_abstract_method(__FILE__)
|
42
|
+
end
|
43
|
+
|
44
|
+
def success(_string)
|
45
|
+
raise_abstract_method(__FILE__)
|
46
|
+
end
|
47
|
+
|
48
|
+
def title(_string)
|
49
|
+
raise_abstract_method(__FILE__)
|
50
|
+
end
|
51
|
+
|
52
|
+
def warn(_string)
|
53
|
+
raise_abstract_method(__FILE__)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacRubyUtils
|
4
|
+
module Speaker
|
5
|
+
module Sender
|
6
|
+
delegate :error, :fatal_error, :info, :infom, :title, :success, :warn, to: :speaker_receiver
|
7
|
+
|
8
|
+
def infov(*args)
|
9
|
+
speaker_receiver.infov(*args)
|
10
|
+
end
|
11
|
+
|
12
|
+
delegate :out, to: :speaker_receiver
|
13
|
+
|
14
|
+
delegate :puts, to: :speaker_receiver
|
15
|
+
|
16
|
+
# Shortcut to [EacRubyUtils::Speaker.current_receiver].
|
17
|
+
#
|
18
|
+
# @return [EacRubyUtils::Speaker::Receiver]
|
19
|
+
def speaker_receiver
|
20
|
+
::EacRubyUtils::Speaker.current_receiver
|
21
|
+
end
|
22
|
+
|
23
|
+
# Options:
|
24
|
+
# +bool+ ([Boolean], default: +false+): requires a answer "yes" or "no".
|
25
|
+
# +list+ ([Hash] or [Array], default: +nil+): requires a answer from a list.
|
26
|
+
# +noecho+ ([Boolean], default: +false+): does not output answer.
|
27
|
+
def input(question, options = {})
|
28
|
+
speaker_receiver.input(question, options)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
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.69.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: 2021-05
|
11
|
+
date: 2021-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -100,6 +100,7 @@ files:
|
|
100
100
|
- lib/eac_ruby_utils/common_constructor/class_initialize.rb
|
101
101
|
- lib/eac_ruby_utils/common_constructor/instance_initialize.rb
|
102
102
|
- lib/eac_ruby_utils/common_constructor/super_args.rb
|
103
|
+
- lib/eac_ruby_utils/context.rb
|
103
104
|
- lib/eac_ruby_utils/contextualizable.rb
|
104
105
|
- lib/eac_ruby_utils/core_ext.rb
|
105
106
|
- lib/eac_ruby_utils/custom_format.rb
|
@@ -169,11 +170,13 @@ files:
|
|
169
170
|
- lib/eac_ruby_utils/patches/module.rb
|
170
171
|
- lib/eac_ruby_utils/patches/module/abstract_methods.rb
|
171
172
|
- lib/eac_ruby_utils/patches/module/common_concern.rb
|
173
|
+
- lib/eac_ruby_utils/patches/module/context.rb
|
172
174
|
- lib/eac_ruby_utils/patches/module/immutable.rb
|
173
175
|
- lib/eac_ruby_utils/patches/module/listable.rb
|
174
176
|
- lib/eac_ruby_utils/patches/module/patch.rb
|
175
177
|
- lib/eac_ruby_utils/patches/module/require_sub.rb
|
176
178
|
- lib/eac_ruby_utils/patches/module/simple_cache.rb
|
179
|
+
- lib/eac_ruby_utils/patches/module/speaker.rb
|
177
180
|
- lib/eac_ruby_utils/patches/object.rb
|
178
181
|
- lib/eac_ruby_utils/patches/object/asserts.rb
|
179
182
|
- lib/eac_ruby_utils/patches/object/debug.rb
|
@@ -183,6 +186,7 @@ files:
|
|
183
186
|
- lib/eac_ruby_utils/patches/object/to_pathname.rb
|
184
187
|
- lib/eac_ruby_utils/patches/pathname.rb
|
185
188
|
- lib/eac_ruby_utils/patches/pathname/basename_sub.rb
|
189
|
+
- lib/eac_ruby_utils/patches/pathname/parent_n.rb
|
186
190
|
- lib/eac_ruby_utils/patches/regexp.rb
|
187
191
|
- lib/eac_ruby_utils/patches/regexp/if_match.rb
|
188
192
|
- lib/eac_ruby_utils/patches/regexp/to_parser.rb
|
@@ -201,6 +205,9 @@ files:
|
|
201
205
|
- lib/eac_ruby_utils/settings_provider.rb
|
202
206
|
- lib/eac_ruby_utils/settings_provider/setting_value.rb
|
203
207
|
- lib/eac_ruby_utils/simple_cache.rb
|
208
|
+
- lib/eac_ruby_utils/speaker.rb
|
209
|
+
- lib/eac_ruby_utils/speaker/receiver.rb
|
210
|
+
- lib/eac_ruby_utils/speaker/sender.rb
|
204
211
|
- lib/eac_ruby_utils/struct.rb
|
205
212
|
- lib/eac_ruby_utils/version.rb
|
206
213
|
- lib/eac_ruby_utils/yaml.rb
|