eac_ruby_utils 0.17.0 → 0.18.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/configs.rb +14 -8
- data/lib/eac_ruby_utils/configs/file.rb +66 -0
- data/lib/eac_ruby_utils/console/docopt_runner/_doc.rb +7 -3
- data/lib/eac_ruby_utils/console/docopt_runner/_settings.rb +8 -3
- data/lib/eac_ruby_utils/console/speaker.rb +7 -1
- data/lib/eac_ruby_utils/console/speaker/_class_methods.rb +7 -0
- data/lib/eac_ruby_utils/console/speaker/node.rb +2 -1
- data/lib/eac_ruby_utils/envs/command/extra_options.rb +1 -1
- data/lib/eac_ruby_utils/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20c8f9d78c4ab21ad894c45d52ee809e6a582402f2a7e2fa865bf15a058727f5
|
4
|
+
data.tar.gz: 9736724bffb18d9779dc7bb8b025011d9efa8a780c6da91b34cc66406cbfe9a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82f9481db69287f556655b1aa6f251a71fd015db4b56fb8777ffccc092595e9d1644f2cc0c6a12dc306a0b1df3a57aa9d582fa6f4945b496daf4ca60b617d22a
|
7
|
+
data.tar.gz: 0ac5b1251e7f2308ef9f3617f82c82842686f7c2b7028f3eea27d32269c56dd7e79a39dd84b8e577a83f3159a29493c0502dd4d03dd551095ecd3f976f766a1e
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'active_support/core_ext/string'
|
4
4
|
require 'yaml'
|
5
|
+
require 'eac_ruby_utils/configs/file'
|
5
6
|
require 'eac_ruby_utils/patches/hash/sym_keys_hash'
|
6
7
|
require 'eac_ruby_utils/paths_hash'
|
7
8
|
require 'eac_ruby_utils/simple_cache'
|
@@ -20,15 +21,15 @@ module EacRubyUtils
|
|
20
21
|
end
|
21
22
|
|
22
23
|
def clear
|
23
|
-
|
24
|
+
file.clear
|
24
25
|
end
|
25
26
|
|
26
27
|
def save
|
27
|
-
|
28
|
+
file.save
|
28
29
|
end
|
29
30
|
|
30
31
|
def load
|
31
|
-
|
32
|
+
file.load
|
32
33
|
end
|
33
34
|
|
34
35
|
def []=(entry_key, entry_value)
|
@@ -36,8 +37,7 @@ module EacRubyUtils
|
|
36
37
|
end
|
37
38
|
|
38
39
|
def write_entry(entry_key, entry_value)
|
39
|
-
|
40
|
-
save if autosave?
|
40
|
+
file.write(entry_key, entry_value)
|
41
41
|
end
|
42
42
|
|
43
43
|
def [](entry_key)
|
@@ -45,19 +45,25 @@ module EacRubyUtils
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def read_entry(entry_key)
|
48
|
-
|
48
|
+
file.read(entry_key)
|
49
49
|
end
|
50
50
|
|
51
51
|
def autosave?
|
52
|
-
|
52
|
+
file.autosave?
|
53
53
|
end
|
54
54
|
|
55
55
|
private
|
56
56
|
|
57
57
|
attr_accessor :data
|
58
58
|
|
59
|
+
def file_uncached
|
60
|
+
::EacRubyUtils::Configs::File.new(
|
61
|
+
storage_path, options
|
62
|
+
)
|
63
|
+
end
|
64
|
+
|
59
65
|
def storage_path_uncached
|
60
|
-
path =
|
66
|
+
path = options_storage_path || default_storage_path
|
61
67
|
return path if ::File.exist?(path) && ::File.size(path).positive?
|
62
68
|
|
63
69
|
::FileUtils.mkdir_p(::File.dirname(path))
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/string'
|
4
|
+
require 'yaml'
|
5
|
+
require 'eac_ruby_utils/patches/hash/sym_keys_hash'
|
6
|
+
require 'eac_ruby_utils/paths_hash'
|
7
|
+
require 'eac_ruby_utils/simple_cache'
|
8
|
+
|
9
|
+
module EacRubyUtils
|
10
|
+
class Configs
|
11
|
+
class File
|
12
|
+
include ::EacRubyUtils::SimpleCache
|
13
|
+
|
14
|
+
attr_reader :path, :options
|
15
|
+
|
16
|
+
# Valid options: [:autosave]
|
17
|
+
def initialize(path, options = {})
|
18
|
+
@path = path
|
19
|
+
@options = options.to_sym_keys_hash.freeze
|
20
|
+
load
|
21
|
+
end
|
22
|
+
|
23
|
+
def clear
|
24
|
+
self.data = ::EacRubyUtils::PathsHash.new({})
|
25
|
+
end
|
26
|
+
|
27
|
+
def save
|
28
|
+
::FileUtils.mkdir_p(::File.dirname(path))
|
29
|
+
::File.write(path, data.to_h.to_yaml)
|
30
|
+
end
|
31
|
+
|
32
|
+
def load
|
33
|
+
self.data = if ::File.exist?(path) && ::File.size(path).positive?
|
34
|
+
::EacRubyUtils::PathsHash.new(YAML.load_file(path))
|
35
|
+
else
|
36
|
+
{}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def []=(entry_key, entry_value)
|
41
|
+
write(entry_key, entry_value)
|
42
|
+
end
|
43
|
+
|
44
|
+
def write(entry_key, entry_value)
|
45
|
+
data[entry_key] = entry_value
|
46
|
+
save if autosave?
|
47
|
+
end
|
48
|
+
|
49
|
+
def [](entry_key)
|
50
|
+
read(entry_key)
|
51
|
+
end
|
52
|
+
|
53
|
+
def read(entry_key)
|
54
|
+
data[entry_key]
|
55
|
+
end
|
56
|
+
|
57
|
+
def autosave?
|
58
|
+
options[:autosave] ? true : false
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
attr_accessor :data
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -10,11 +10,15 @@ module EacRubyUtils
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def target_doc
|
13
|
-
source_doc.gsub(PROGRAM_MACRO,
|
13
|
+
source_doc.gsub(PROGRAM_MACRO, target_program_name).strip + "\n"
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
|
16
|
+
def source_program_name
|
17
|
+
setting_value(:program_name, false)
|
18
|
+
end
|
19
|
+
|
20
|
+
def target_program_name
|
21
|
+
[source_program_name, ENV['PROGRAM_NAME'], $PROGRAM_NAME].find(&:present?)
|
18
22
|
end
|
19
23
|
end
|
20
24
|
end
|
@@ -8,14 +8,15 @@ module EacRubyUtils
|
|
8
8
|
private
|
9
9
|
|
10
10
|
def setting_value(key, required = true)
|
11
|
-
%i[setting_from_argument setting_from_constant].each do |method|
|
11
|
+
%i[setting_from_method setting_from_argument setting_from_constant].each do |method|
|
12
12
|
value = send(method, key)
|
13
13
|
return value if value
|
14
14
|
end
|
15
15
|
return nil unless required
|
16
16
|
|
17
|
-
raise "Setting \"#{key}\" not found.
|
18
|
-
"
|
17
|
+
raise "Setting \"#{key}\" not found. Implement a \"#{key}\" method" \
|
18
|
+
", declare a #{setting_constant(key, true)} constant" \
|
19
|
+
"or pass a #{key.to_sym} option to #{self.class.name}.new() method."
|
19
20
|
end
|
20
21
|
|
21
22
|
def setting_from_argument(key)
|
@@ -31,6 +32,10 @@ module EacRubyUtils
|
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
35
|
+
def setting_from_method(key)
|
36
|
+
respond_to?(key) ? send(key) : nil
|
37
|
+
end
|
38
|
+
|
34
39
|
def setting_constant(key, fullname = false)
|
35
40
|
name = key.to_s.underscore.upcase
|
36
41
|
name = "#{self.class.name}::#{name}" if fullname
|
@@ -11,8 +11,14 @@ module EacRubyUtils
|
|
11
11
|
module Console
|
12
12
|
# https://github.com/fazibear/colorize
|
13
13
|
module Speaker
|
14
|
+
def on_speaker_node(&block)
|
15
|
+
::EacRubyUtils::Console::Speaker.on_node(&block)
|
16
|
+
end
|
17
|
+
|
14
18
|
def puts(string = '')
|
15
|
-
|
19
|
+
string.to_s.each_line do |line|
|
20
|
+
current_node.stderr.puts(current_node.stderr_line_prefix.to_s + line)
|
21
|
+
end
|
16
22
|
end
|
17
23
|
|
18
24
|
def out(string = '')
|
@@ -10,6 +10,13 @@ module EacRubyUtils
|
|
10
10
|
nodes_stack.last
|
11
11
|
end
|
12
12
|
|
13
|
+
def on_node(&block)
|
14
|
+
push
|
15
|
+
yield(*(block.arity.zero? ? [] : [current_node]))
|
16
|
+
ensure
|
17
|
+
pop
|
18
|
+
end
|
19
|
+
|
13
20
|
def push
|
14
21
|
nodes_stack << ::EacRubyUtils::Console::Speaker::Node.new
|
15
22
|
current_node
|
@@ -6,12 +6,13 @@ module EacRubyUtils
|
|
6
6
|
module Console
|
7
7
|
module Speaker
|
8
8
|
class Node
|
9
|
-
attr_accessor :stdin, :stdout, :stderr
|
9
|
+
attr_accessor :stdin, :stdout, :stderr, :stderr_line_prefix
|
10
10
|
|
11
11
|
def initialize(parent = nil)
|
12
12
|
self.stdin = parent.if_present(STDIN, &:stdin)
|
13
13
|
self.stdout = parent.if_present(STDOUT, &:stdout)
|
14
14
|
self.stderr = parent.if_present(STDERR, &:stderr)
|
15
|
+
self.stderr_line_prefix = parent.if_present('', &:stderr_line_prefix)
|
15
16
|
end
|
16
17
|
|
17
18
|
def configure
|
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.18.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:
|
11
|
+
date: 2020-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- lib/eac_ruby_utils/arguments_consumer.rb
|
120
120
|
- lib/eac_ruby_utils/common_constructor.rb
|
121
121
|
- lib/eac_ruby_utils/configs.rb
|
122
|
+
- lib/eac_ruby_utils/configs/file.rb
|
122
123
|
- lib/eac_ruby_utils/console.rb
|
123
124
|
- lib/eac_ruby_utils/console/configs.rb
|
124
125
|
- lib/eac_ruby_utils/console/docopt_runner.rb
|