eac_ruby_utils 0.65.0 → 0.69.1
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/boolean.rb +1 -1
- data/lib/eac_ruby_utils/context.rb +31 -0
- data/lib/eac_ruby_utils/contextualizable.rb +21 -0
- 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 +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e531361347677f1585f1ceecd5b8230e44b0db18d70dbb3b685123b7b6beaf5
|
4
|
+
data.tar.gz: 9a49e7f6e59bed4e3a4bc9421decbf1bb832db7e527df3f249e0e3f215bb3c71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05b20139daca89f913ab309c123c18684c08e1b595f4e64011ec5cc4fe11dced0ecfd84554f5ed0dc6f8f0323f284639d3eaa39e3df481fbde5c7cdae426fe49
|
7
|
+
data.tar.gz: 41ec207a6adc45ce9f305d96fd17650530355848691b067a4fc21569b97492ae8ba7579ac3ea2b25fff5e99bb6c4ec1f56226820038ded542551e31b6e6a2ad5
|
@@ -6,7 +6,7 @@ module EacRubyUtils
|
|
6
6
|
def parse(value)
|
7
7
|
return parse_string(value) if value.is_a?(::String)
|
8
8
|
return parse_string(value.to_s) if value.is_a?(::Symbol)
|
9
|
-
return parse_number(value) if value.is_a?(::
|
9
|
+
return parse_number(value) if value.is_a?(::Numeric)
|
10
10
|
|
11
11
|
value ? true : false
|
12
12
|
end
|
@@ -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
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/context'
|
4
|
+
|
5
|
+
module EacRubyUtils
|
6
|
+
module Contextualizable
|
7
|
+
common_concern
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def context
|
11
|
+
@context ||= ::EacRubyUtils::Context.new
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module InstanceMethods
|
16
|
+
def context
|
17
|
+
self.class.context
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
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.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: 2021-
|
11
|
+
date: 2021-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -100,6 +100,8 @@ 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
|
104
|
+
- lib/eac_ruby_utils/contextualizable.rb
|
103
105
|
- lib/eac_ruby_utils/core_ext.rb
|
104
106
|
- lib/eac_ruby_utils/custom_format.rb
|
105
107
|
- lib/eac_ruby_utils/envs.rb
|
@@ -168,11 +170,13 @@ files:
|
|
168
170
|
- lib/eac_ruby_utils/patches/module.rb
|
169
171
|
- lib/eac_ruby_utils/patches/module/abstract_methods.rb
|
170
172
|
- lib/eac_ruby_utils/patches/module/common_concern.rb
|
173
|
+
- lib/eac_ruby_utils/patches/module/context.rb
|
171
174
|
- lib/eac_ruby_utils/patches/module/immutable.rb
|
172
175
|
- lib/eac_ruby_utils/patches/module/listable.rb
|
173
176
|
- lib/eac_ruby_utils/patches/module/patch.rb
|
174
177
|
- lib/eac_ruby_utils/patches/module/require_sub.rb
|
175
178
|
- lib/eac_ruby_utils/patches/module/simple_cache.rb
|
179
|
+
- lib/eac_ruby_utils/patches/module/speaker.rb
|
176
180
|
- lib/eac_ruby_utils/patches/object.rb
|
177
181
|
- lib/eac_ruby_utils/patches/object/asserts.rb
|
178
182
|
- lib/eac_ruby_utils/patches/object/debug.rb
|
@@ -182,6 +186,7 @@ files:
|
|
182
186
|
- lib/eac_ruby_utils/patches/object/to_pathname.rb
|
183
187
|
- lib/eac_ruby_utils/patches/pathname.rb
|
184
188
|
- lib/eac_ruby_utils/patches/pathname/basename_sub.rb
|
189
|
+
- lib/eac_ruby_utils/patches/pathname/parent_n.rb
|
185
190
|
- lib/eac_ruby_utils/patches/regexp.rb
|
186
191
|
- lib/eac_ruby_utils/patches/regexp/if_match.rb
|
187
192
|
- lib/eac_ruby_utils/patches/regexp/to_parser.rb
|
@@ -200,6 +205,9 @@ files:
|
|
200
205
|
- lib/eac_ruby_utils/settings_provider.rb
|
201
206
|
- lib/eac_ruby_utils/settings_provider/setting_value.rb
|
202
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
|
203
211
|
- lib/eac_ruby_utils/struct.rb
|
204
212
|
- lib/eac_ruby_utils/version.rb
|
205
213
|
- lib/eac_ruby_utils/yaml.rb
|