eac_ruby_utils 0.15.0 → 0.16.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c932e97f7a56a87ac479e6897edc7726b810e7031c88049bcdaa674e3a47d8c
|
4
|
+
data.tar.gz: cf4eb48992f065f1ba1bc0fbd5c76951679c30f8133b3f2c36f7d82e162e27fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dde3dde0b173519bc0fcd6d799cd6896895087cce78310bd733fde0848b137674d5d11ff4cda4cc523a917ce7a0ca4228727c8c7e3d660c68ecbee13da02c93c
|
7
|
+
data.tar.gz: 9f4e4f8f8a9f48d2817f0496be6617860256888fc2a50abb37306837872e3f23aef35eb1f4bf654667b352379d90cd6312f64177e700d06670439772dbfb643e
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'active_support/callbacks'
|
4
|
+
|
3
5
|
module EacRubyUtils
|
4
6
|
class CommonConstructor
|
5
7
|
attr_reader :args, :options
|
@@ -25,14 +27,18 @@ module EacRubyUtils
|
|
25
27
|
end
|
26
28
|
|
27
29
|
def setup_class_initialize(klass)
|
30
|
+
klass.include(::ActiveSupport::Callbacks)
|
31
|
+
klass.define_callbacks :initialize
|
28
32
|
klass.class_eval initialize_method_code, __FILE__, __LINE__
|
29
33
|
end
|
30
34
|
|
31
35
|
def initialize_method_code
|
32
36
|
b = "def initialize(#{initialize_method_args_code})\n"
|
37
|
+
b += " run_callbacks :initialize do\n"
|
33
38
|
initialize_method_args.each do |arg|
|
34
39
|
b += " self.#{arg} = #{arg}\n"
|
35
40
|
end
|
41
|
+
b += " end\n"
|
36
42
|
b += "end\n"
|
37
43
|
b
|
38
44
|
end
|
@@ -54,7 +54,7 @@ module EacRubyUtils
|
|
54
54
|
|
55
55
|
def storage_path_uncached
|
56
56
|
path = options[:storage_path] || default_storage_path
|
57
|
-
return path if ::File.exist?(path)
|
57
|
+
return path if ::File.exist?(path) && ::File.size(path).positive?
|
58
58
|
|
59
59
|
::FileUtils.mkdir_p(::File.dirname(path))
|
60
60
|
::File.write(path, {}.to_yaml)
|
@@ -1,7 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'eac_ruby_utils/common_constructor'
|
3
4
|
require 'eac_ruby_utils/configs'
|
4
5
|
require 'eac_ruby_utils/console/speaker'
|
6
|
+
require 'eac_ruby_utils/options_consumer'
|
7
|
+
require 'eac_ruby_utils/patches/object/asserts'
|
8
|
+
require 'eac_ruby_utils/simple_cache'
|
5
9
|
|
6
10
|
module EacRubyUtils
|
7
11
|
module Console
|
@@ -24,8 +28,9 @@ module EacRubyUtils
|
|
24
28
|
|
25
29
|
attr_reader :configs
|
26
30
|
|
27
|
-
def initialize(configs_key)
|
28
|
-
|
31
|
+
def initialize(configs_key, options = {})
|
32
|
+
options.assert_argument(::Hash, 'options')
|
33
|
+
@configs = ::EacRubyUtils::Configs.new(configs_key, options.merge(autosave: true))
|
29
34
|
end
|
30
35
|
|
31
36
|
def read_password(entry_key, options = {})
|
@@ -38,6 +43,7 @@ module EacRubyUtils
|
|
38
43
|
end
|
39
44
|
|
40
45
|
def read_entry(entry_key, options = {})
|
46
|
+
options = ReadEntryOptions.new(options)
|
41
47
|
unless options[:noenv]
|
42
48
|
envvar_value = envvar_read_entry(entry_key)
|
43
49
|
return envvar_value if envvar_value.present?
|
@@ -46,7 +52,7 @@ module EacRubyUtils
|
|
46
52
|
return stored_value if stored_value
|
47
53
|
return read_entry_from_console(entry_key, options) unless options[:noinput]
|
48
54
|
|
49
|
-
raise "No value found for entry \"#{entry_key}\""
|
55
|
+
raise "No value found for entry \"#{entry_key}\"" if options[:required]
|
50
56
|
end
|
51
57
|
|
52
58
|
def store_passwords?
|
@@ -87,10 +93,43 @@ module EacRubyUtils
|
|
87
93
|
end
|
88
94
|
|
89
95
|
def entry_value_from_input(entry_key, options)
|
90
|
-
entry_value = request_input("Value for entry \"#{entry_key}\"",
|
96
|
+
entry_value = request_input("Value for entry \"#{entry_key}\"",
|
97
|
+
options.request_input_options)
|
91
98
|
warn('Entered value is blank') if entry_value.blank?
|
92
99
|
entry_value
|
93
100
|
end
|
101
|
+
|
102
|
+
class ReadEntryOptions
|
103
|
+
include ::EacRubyUtils::SimpleCache
|
104
|
+
::EacRubyUtils::CommonConstructor.new(:options).setup_class(self)
|
105
|
+
|
106
|
+
DEFAULT_VALUES = {
|
107
|
+
before_input: nil, bool: false, list: false, noecho: false, noenv: false, noinput: false,
|
108
|
+
required: true, validator: nil
|
109
|
+
}.freeze
|
110
|
+
|
111
|
+
def [](key)
|
112
|
+
values.fetch(key.to_sym)
|
113
|
+
end
|
114
|
+
|
115
|
+
def request_input_options
|
116
|
+
values.slice(:bool, :list, :noecho)
|
117
|
+
end
|
118
|
+
|
119
|
+
private
|
120
|
+
|
121
|
+
def values_uncached
|
122
|
+
consumer = ::EacRubyUtils::OptionsConsumer.new(options)
|
123
|
+
r = {}
|
124
|
+
DEFAULT_VALUES.each do |key, default_value|
|
125
|
+
value = consumer.consume(key)
|
126
|
+
value = default_value if value.nil?
|
127
|
+
r[key] = value
|
128
|
+
end
|
129
|
+
consumer.validate
|
130
|
+
r
|
131
|
+
end
|
132
|
+
end
|
94
133
|
end
|
95
134
|
end
|
96
135
|
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.16.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: 2019-
|
11
|
+
date: 2019-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|