eac_ruby_utils 0.9.0 → 0.10.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: 9290fda1cce697dcfd049b6a8085af55f0ca059d64d183b7571a0f5cbfa9a820
4
- data.tar.gz: 54679bb172f9c3a2dcac08d642fc0a23dec10142384dff4b6e7f4c72db21622b
3
+ metadata.gz: 50b84cf497dba566fde8efbde41a76b69ff81620a858245a7b2fd02d9d62c2f0
4
+ data.tar.gz: '084a436c1f32672730d9369e06985b95b85f600d263e2ff1f92c24a90f04fcdf'
5
5
  SHA512:
6
- metadata.gz: e0611daf87bdb28ca44827934496a9d546b5f9220a0807d80416b61a9b30b282333cbdd9d6699644c47924704d428f9e2a9f18eba4f1c3eab74dc0c432e6efc8
7
- data.tar.gz: 4402ebebc43b4b862951a39c6213c5c13f2f86fc0784deadbf49a78408e36c3827e40c73e66552bb7313c6603421cb65c8cd3c24fbec8f391ee27048496d3692
6
+ metadata.gz: fa0100d893665b4a59995d0ccb16702629154ce247cb4c8d9bdce5b970cdf8dca9b89089bdabc0ef7263a7a80eced31bc05f9ef9fd66b25549d0cebae8c3f61d
7
+ data.tar.gz: bd97c8a6d1bf93cfed0ee45e789ef8f1551a1538fc9ec23f1f9aea46a7df2958ff58d032867c087d6f39976775249068b1a3a1109dd9524558ad9312835e6f6a
@@ -8,6 +8,18 @@ module EacRubyUtils
8
8
  class Configs
9
9
  include ::EacRubyUtils::Console::Speaker
10
10
 
11
+ class << self
12
+ def entry_key_to_envvar_name(entry_key)
13
+ path = if entry_key.is_a?(::Array)
14
+ entry_key
15
+ else
16
+ ::EacRubyUtils::PathsHash.parse_entry_key(entry_key)
17
+ end
18
+ path.join('_').gsub(/[^a-z0-9_]/i, '').gsub(/\A_+/, '').gsub(/_+\z/, '')
19
+ .gsub(/_{2,}/, '_').upcase
20
+ end
21
+ end
22
+
11
23
  STORE_PASSWORDS_KEY = 'core.store_passwords'
12
24
 
13
25
  attr_reader :configs
@@ -26,12 +38,14 @@ module EacRubyUtils
26
38
  end
27
39
 
28
40
  def read_entry(entry_key, options = {})
41
+ unless options[:noenv]
42
+ envvar_value = envvar_read_entry(entry_key)
43
+ return envvar_value if envvar_value.present?
44
+ end
29
45
  stored_value = configs.read_entry(entry_key)
30
46
  return stored_value if stored_value
31
- options[:before_input].call if options[:before_input].present?
32
- entry_value = looped_entry_value_from_input(entry_key, options)
33
- configs.write_entry(entry_key, entry_value)
34
- entry_value
47
+ return read_entry_from_console(entry_key, options) unless options[:noinput]
48
+ raise "No value found for entry \"#{entry_key}\""
35
49
  end
36
50
 
37
51
  def store_passwords?
@@ -44,6 +58,17 @@ module EacRubyUtils
44
58
 
45
59
  protected
46
60
 
61
+ def envvar_read_entry(entry_key)
62
+ ENV[self.class.entry_key_to_envvar_name(entry_key)]
63
+ end
64
+
65
+ def read_entry_from_console(entry_key, options)
66
+ options[:before_input].call if options[:before_input].present?
67
+ entry_value = looped_entry_value_from_input(entry_key, options)
68
+ configs.write_entry(entry_key, entry_value)
69
+ entry_value
70
+ end
71
+
47
72
  def store_password_banner
48
73
  infom 'Do you wanna to store passwords?'
49
74
  infom "Warning: the passwords will be store in clear text in \"#{configs.storage_path}\""
@@ -14,7 +14,7 @@ module EacRubyUtils
14
14
  end
15
15
 
16
16
  def program_name
17
- setting_value(:program_name, false) || ENV['PROGRAM_NAME'] || $PROGRAM_NAME
17
+ [setting_value(:program_name, false), ENV['PROGRAM_NAME'], $PROGRAM_NAME].find(&:present?)
18
18
  end
19
19
  end
20
20
  end
@@ -30,9 +30,9 @@ module EacRubyUtils
30
30
  end
31
31
  end
32
32
 
33
- def setting_constant(key, _fullname = false)
33
+ def setting_constant(key, fullname = false)
34
34
  name = key.to_s.underscore.upcase
35
- name = "#{self.class.name}::#{name}"
35
+ name = "#{self.class.name}::#{name}" if fullname
36
36
  name
37
37
  end
38
38
  end
@@ -46,7 +46,7 @@ module EacRubyUtils
46
46
  STDERR.write("\n")
47
47
  r
48
48
  else
49
- gets.chomp.strip
49
+ STDIN.gets.chomp.strip
50
50
  end
51
51
  end
52
52
 
@@ -1,8 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Object
4
- def assert_argument(klass, argument_name)
5
- return if is_a?(klass)
4
+ # Raises a ArgumentError if +self+ is not a +klass+.
5
+ #
6
+ # @return +self+
7
+ def assert_argument(klass, argument_name = 'unknown_argument_name')
8
+ return self if is_a?(klass)
6
9
  raise ::ArgumentError,
7
10
  "Argument \"#{argument_name}\" is not a #{klass}" \
8
11
  "(Actual class: #{self.class}, actual value: #{self})"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.9.0'
4
+ VERSION = '0.10.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.9.0
4
+ version: 0.10.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-07-31 00:00:00.000000000 Z
11
+ date: 2019-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport