eac_ruby_utils 0.41.0 → 0.45.1

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: 8e04909bde0d65f8b8615601194b4fb9c1fb3b6b56f6bf02cd98103fe0510e7b
4
- data.tar.gz: 902d0c69a54f0a0330c4e47afa498501b02beec6367c6d952f6d72f8388b74c5
3
+ metadata.gz: 9561b2dad59c16d8c53850c232326d7dcf2455b0aa2204dd20562859f5270e2b
4
+ data.tar.gz: f26fbd157cb4eaf343eb45333015180d0e339c61d7b9ae35fd421e183a9e3573
5
5
  SHA512:
6
- metadata.gz: cbaf478b74fbb77fff8682b733685773ad8c3de4eac8e5fc9c2adcca81fbeac56a5e4df330c0ffb60097f1c3d75b371270814b52ca1bd54ef77fa417adf55284
7
- data.tar.gz: 947edd1f4ba4f942ba78ed5e17f99b95d1d89f456426437efa6c3eb35128c12b312fb628f962f0e123a38d8ea37c6fa7a135d1c4c4d7d1b6f9b6449e465458ed
6
+ metadata.gz: f712437c149c25fb335e64a0a636205540ee66499b816d42b0cc0f88d48dcb47173dcd146ff0877c97039e71ede7e71d1bbed43ee618750ffa29927da4bb40b4
7
+ data.tar.gz: 24f060d6e574bc59bd892560ff9fbbc93a2518037b43ee026080cea301a5bf1d298614302fa6f8e20e0b7f913e1e16bec012263227ece7bce534410f0657ea82
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacRubyUtils
4
+ class Boolean
5
+ class << self
6
+ def parse(value)
7
+ return parse_string(value) if value.is_a?(::String)
8
+ return parse_string(value.to_s) if value.is_a?(::Symbol)
9
+ return parse_number(value) if value.is_a?(::Number)
10
+
11
+ value ? true : false
12
+ end
13
+
14
+ private
15
+
16
+ def parse_string(value)
17
+ ['', 'n', 'no', 'f', 'false'].include?(value.strip.downcase) ? false : true
18
+ end
19
+
20
+ def parse_number(value)
21
+ value.zero?
22
+ end
23
+ end
24
+
25
+ attr_reader :value
26
+
27
+ def initialize(value)
28
+ @value = self.class.parse(value)
29
+ end
30
+ end
31
+ end
@@ -14,6 +14,12 @@ module EacRubyUtils
14
14
  class DocoptRunner
15
15
  include ::EacRubyUtils::Contextualizable
16
16
 
17
+ class << self
18
+ def create(settings = {})
19
+ new(settings)
20
+ end
21
+ end
22
+
17
23
  attr_reader :settings
18
24
 
19
25
  def initialize(settings = {})
@@ -3,11 +3,11 @@
3
3
  module EacRubyUtils
4
4
  module Console
5
5
  class DocoptRunner
6
- DOCOPT_ERROR_EXIT_CODE = 0x22220000
6
+ DOCOPT_ERROR_EXIT_CODE = 0xC0
7
7
 
8
8
  class << self
9
9
  def run(options = {})
10
- new(options).send(:run)
10
+ create(options).send(:run)
11
11
  rescue Docopt::Exit => e
12
12
  STDERR.write(e.message + "\n")
13
13
  ::Kernel.exit(DOCOPT_ERROR_EXIT_CODE) # rubocop:disable Rails/Exit
@@ -25,6 +25,8 @@ module EacRubyUtils
25
25
  end
26
26
 
27
27
  module SubcommandsSupport
28
+ EXTRA_AVAILABLE_SUBCOMMANDS_METHOD_NAME = :extra_available_subcommands
29
+
28
30
  def check_subcommands_arg
29
31
  if subcommand_arg_as_list?
30
32
  singleton_class.include(SubcommandsSupport::SubcommandArgAsList)
@@ -43,7 +45,7 @@ module EacRubyUtils
43
45
  end
44
46
 
45
47
  def subcommand
46
- @subcommand ||= subcommand_class_name(subcommand_name).constantize.new(
48
+ @subcommand ||= subcommand_class_name(subcommand_name).constantize.create(
47
49
  argv: subcommand_args,
48
50
  program_name: subcommand_program,
49
51
  parent: self
@@ -77,7 +79,11 @@ module EacRubyUtils
77
79
  end
78
80
 
79
81
  def available_subcommands
80
- (setting_value(:subcommands, false) || auto_available_subcommands).sort
82
+ r = ::Set.new(setting_value(:subcommands, false) || auto_available_subcommands)
83
+ if respond_to?(EXTRA_AVAILABLE_SUBCOMMANDS_METHOD_NAME, true)
84
+ r += send(EXTRA_AVAILABLE_SUBCOMMANDS_METHOD_NAME)
85
+ end
86
+ r.sort
81
87
  end
82
88
 
83
89
  def auto_available_subcommands
@@ -3,13 +3,15 @@
3
3
  require 'addressable'
4
4
  require 'eac_ruby_utils/envs/base_env'
5
5
  require 'eac_ruby_utils/patches/object/if_present'
6
+ require 'eac_ruby_utils/patches/module/require_sub'
6
7
  require 'net/ssh'
7
8
  require 'shellwords'
8
9
 
9
10
  module EacRubyUtils
10
11
  module Envs
11
12
  class SshEnv < ::EacRubyUtils::Envs::BaseEnv
12
- IDENTITITY_FILE_OPTION = 'IdentityFile'
13
+ require_sub __FILE__, include_modules: true
14
+
13
15
  USER_PATTERN = /[a-z_][a-z0-9_-]*/.freeze
14
16
  HOSTNAME_PATTERN = /[^@]+/.freeze
15
17
  USER_HOSTNAME_PATTERN = /\A(?:(#{USER_PATTERN})@)?(#{HOSTNAME_PATTERN})\z/.freeze
@@ -51,20 +53,16 @@ module EacRubyUtils
51
53
  private
52
54
 
53
55
  def ssh_command_line
54
- r = %w[ssh]
55
- r += ['-p', uri.port] if uri.port.present?
56
- ssh_identity_file.if_present { |v| r += ['-i', v] }
57
- r += ssh_command_line_options
58
- r << user_hostname_uri
59
- r.map { |a| Shellwords.escape(a) }.join(' ')
56
+ (%w[ssh] +
57
+ %w[nodasho dasho port].flat_map { |m| send("ssh_command_line_#{m}_args") } +
58
+ [user_hostname_uri])
59
+ .map { |a| Shellwords.escape(a) }.join(' ')
60
60
  end
61
61
 
62
- def ssh_command_line_options
63
- r = []
64
- uri.query_values&.each do |k, v|
65
- r += ['-o', "#{k}=#{v}"] unless k == IDENTITITY_FILE_OPTION
62
+ def ssh_command_line_port_args
63
+ uri.port.if_present([]) do |v|
64
+ ['-p', v]
66
65
  end
67
- r
68
66
  end
69
67
 
70
68
  def user_hostname_uri
@@ -72,12 +70,6 @@ module EacRubyUtils
72
70
  r = "#{uri.user}@#{r}" if uri.user.present?
73
71
  r
74
72
  end
75
-
76
- def ssh_identity_file
77
- uri.query_values.if_present do |v|
78
- v[IDENTITITY_FILE_OPTION]
79
- end
80
- end
81
73
  end
82
74
  end
83
75
  end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/patches/module/common_concern'
4
+ require 'eac_ruby_utils/patches/module/simple_cache'
5
+
6
+ module EacRubyUtils
7
+ module Envs
8
+ class SshEnv < ::EacRubyUtils::Envs::BaseEnv
9
+ module DashoOptions
10
+ common_concern
11
+
12
+ module ClassMethods
13
+ def add_nodasho_option(name)
14
+ return if nodasho_options.include?(name)
15
+
16
+ nodasho_options << name
17
+ const_set("#{name.underscore}_option".upcase, name)
18
+ end
19
+
20
+ def nodasho_options
21
+ @nodasho_options ||= []
22
+ end
23
+ end
24
+
25
+ module InstanceMethods
26
+ def ssh_command_line_dasho_args
27
+ r = []
28
+ uri.query_values&.each do |k, v|
29
+ r += ['-o', "#{k}=#{v}"] unless nodasho_options.include?(k)
30
+ end
31
+ r
32
+ end
33
+
34
+ def ssh_command_line_nodasho_args
35
+ nodasho_options.flat_map do |option_name|
36
+ uri_query_value(option_name).if_present([]) do |option_value|
37
+ send("ssh_command_line_#{option_name.underscore}_args", option_value)
38
+ end
39
+ end
40
+ end
41
+
42
+ def nodasho_options
43
+ self.class.nodasho_options
44
+ end
45
+
46
+ def uri_query_value(name)
47
+ uri.query_values.if_present { |v| v[name] }
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/concern'
4
+ require 'eac_ruby_utils/envs/ssh_env/dasho_options'
5
+ require 'eac_ruby_utils/listable'
6
+ require 'eac_ruby_utils/patches/object/if_present'
7
+
8
+ module EacRubyUtils
9
+ module Envs
10
+ class SshEnv < ::EacRubyUtils::Envs::BaseEnv
11
+ module IdentityFile
12
+ extend ::ActiveSupport::Concern
13
+
14
+ included do
15
+ include ::EacRubyUtils::Envs::SshEnv::DashoOptions
16
+ add_nodasho_option('IdentityFile')
17
+ end
18
+
19
+ def ssh_command_line_identity_file_args(value)
20
+ ['-i', value]
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/concern'
4
+ require 'eac_ruby_utils/boolean'
5
+ require 'eac_ruby_utils/envs/ssh_env/dasho_options'
6
+
7
+ module EacRubyUtils
8
+ module Envs
9
+ class SshEnv < ::EacRubyUtils::Envs::BaseEnv
10
+ module Quiet
11
+ extend ::ActiveSupport::Concern
12
+
13
+ included do
14
+ include ::EacRubyUtils::Envs::SshEnv::DashoOptions
15
+ add_nodasho_option('Quiet')
16
+ end
17
+
18
+ def ssh_command_line_quiet_args(value)
19
+ ::EacRubyUtils::Boolean.parse(value) ? ['-q'] : []
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/concern'
4
+ require 'eac_ruby_utils/envs/ssh_env/dasho_options'
5
+ require 'eac_ruby_utils/listable'
6
+ require 'eac_ruby_utils/patches/object/if_present'
7
+
8
+ module EacRubyUtils
9
+ module Envs
10
+ class SshEnv < ::EacRubyUtils::Envs::BaseEnv
11
+ module Terminal
12
+ extend ::ActiveSupport::Concern
13
+
14
+ included do
15
+ include ::EacRubyUtils::Envs::SshEnv::DashoOptions
16
+ add_nodasho_option('Terminal')
17
+ include ::EacRubyUtils::Listable
18
+ lists.add_string :terminal_option, :auto, :disable, :enable, :force
19
+ end
20
+
21
+ def ssh_command_line_terminal_args(value)
22
+ self.class.lists.terminal_option.value_validate!(value)
23
+ case value
24
+ when TERMINAL_OPTION_AUTO then ENV['TERM'].present? ? %w[-t] : []
25
+ when TERMINAL_OPTION_DISABLE then ['-T']
26
+ when TERMINAL_OPTION_ENABLE then ['-t']
27
+ when TERMINAL_OPTION_FORCE then ['-tt']
28
+ else raise "Invalid conditional branch: #{value}"
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacRubyUtils
4
+ class Inflector
5
+ class << self
6
+ VARIABLE_NAME_PATTERN = /[_a-z][_a-z0-9]*/i.freeze
7
+
8
+ def variableize(string)
9
+ r = string.gsub(/[^_a-z0-9]/i, '_').gsub(/_+/, '_').gsub(/_\z/, '').gsub(/\A_/, '').downcase
10
+ m = VARIABLE_NAME_PATTERN.match(r)
11
+ return r if m
12
+
13
+ raise ::ArgumentError, "Invalid variable name \"#{r}\" was generated " \
14
+ "from string \"#{string}\""
15
+ end
16
+ end
17
+ end
18
+ end
@@ -33,6 +33,11 @@ module EacRubyUtils
33
33
  find_list_by_method(name) || super
34
34
  end
35
35
 
36
+ def hash_keys_validate!(hash, error_class = ::StandardError)
37
+ hash.keys.each { |key| value_validate!(key, error_class) }
38
+ hash
39
+ end
40
+
36
41
  def i18n_key
37
42
  "eac_ruby_utils.listable.#{class_i18n_key}.#{item}"
38
43
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'eac_ruby_utils/inflector'
4
+
3
5
  module EacRubyUtils
4
6
  module Listable
5
7
  class Value
@@ -16,8 +18,7 @@ module EacRubyUtils
16
18
  end
17
19
 
18
20
  def constant_name
19
- "#{@list.item}_#{@key}".gsub(/[^a-z0-9_]/, '_').gsub(/_+/, '_')
20
- .gsub(/(?:\A_|_\z)/, '').upcase
21
+ ::EacRubyUtils::Inflector.variableize("#{@list.item}_#{@key}").upcase
21
22
  end
22
23
 
23
24
  def label
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/object/blank'
4
+
5
+ class Object
6
+ # @return +block.call(self.method_name)+ if +self+ responds to +method_name+, +default_value+
7
+ # otherwise.
8
+ def if_respond(method_name, default_value = nil)
9
+ return default_value unless respond_to?(method_name)
10
+
11
+ value = send(method_name)
12
+
13
+ block_given? ? yield(value) : value
14
+ end
15
+
16
+ # @return +yield+ if +self+ is blank.
17
+ def if_blank
18
+ return yield if blank? && block_given?
19
+
20
+ self
21
+ end
22
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+ ::EacRubyUtils.require_sub __FILE__
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/inflector'
4
+
5
+ class String
6
+ def variableize
7
+ ::EacRubyUtils::Inflector.variableize(self)
8
+ end
9
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'active_support/inflector'
4
+ require 'eac_ruby_utils/listable'
4
5
 
5
6
  module EacRubyUtils
6
7
  class << self
@@ -10,15 +11,14 @@ module EacRubyUtils
10
11
  end
11
12
 
12
13
  class RequireSub
13
- BASE_OPTION_KEY = :base
14
- INCLUDE_MODULES_OPTION_KEY = :include_modules
15
- REQUIRE_DEPENDENCY_OPTION_KEY = :require_dependency
14
+ include ::EacRubyUtils::Listable
15
+ lists.add_symbol :option, :base, :include_modules, :require_dependency
16
16
 
17
17
  attr_reader :file, :options
18
18
 
19
19
  def initialize(file, options = {})
20
20
  @file = file
21
- @options = options
21
+ @options = self.class.lists.option.hash_keys_validate!(options)
22
22
  end
23
23
 
24
24
  def apply
@@ -29,7 +29,7 @@ module EacRubyUtils
29
29
  private
30
30
 
31
31
  def active_support_require(path)
32
- return false unless options[REQUIRE_DEPENDENCY_OPTION_KEY]
32
+ return false unless options[OPTION_REQUIRE_DEPENDENCY]
33
33
 
34
34
  ::Kernel.require_dependency(path)
35
35
  true
@@ -46,7 +46,7 @@ module EacRubyUtils
46
46
  end
47
47
 
48
48
  def include_modules
49
- return unless options[INCLUDE_MODULES_OPTION_KEY]
49
+ return unless options[OPTION_INCLUDE_MODULES]
50
50
 
51
51
  base.constants.each do |constant_name|
52
52
  constant = base.const_get(constant_name)
@@ -57,11 +57,11 @@ module EacRubyUtils
57
57
  end
58
58
 
59
59
  def base
60
- options[BASE_OPTION_KEY] || raise('Option :base not setted')
60
+ options[OPTION_BASE] || raise('Option :base not setted')
61
61
  end
62
62
 
63
63
  def base?
64
- options[BASE_OPTION_KEY] ? true : false
64
+ options[OPTION_BASE] ? true : false
65
65
  end
66
66
 
67
67
  def kernel_require(path)
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/hash_with_indifferent_access'
4
+ require 'active_support/core_ext/object/blank'
5
+
6
+ module EacRubyUtils
7
+ class Struct
8
+ def initialize(initial_data = {})
9
+ self.data = ::ActiveSupport::HashWithIndifferentAccess.new(initial_data)
10
+ end
11
+
12
+ def [](key)
13
+ key, bool = parse_key(key)
14
+ bool ? self[key].present? : data[key]
15
+ end
16
+
17
+ def fetch(key)
18
+ key, bool = parse_key(key)
19
+ bool ? fetch(key).present? : data.fetch(key)
20
+ end
21
+
22
+ def method_missing(method_name, *arguments, &block)
23
+ property_method?(method_name) ? fetch(method_name) : super
24
+ end
25
+
26
+ def respond_to_missing?(method_name, include_private = false)
27
+ property_method?(method_name) || super
28
+ end
29
+
30
+ private
31
+
32
+ attr_accessor :data
33
+
34
+ def parse_key(key)
35
+ m = /\A(.+)\?\z/.match(key.to_s)
36
+ [(m ? m[1] : key.to_s).to_sym, m ? true : false]
37
+ end
38
+
39
+ def property_method?(key)
40
+ property_methods.include?(key.to_sym)
41
+ end
42
+
43
+ def property_methods
44
+ data.keys.flat_map { |k| [k.to_sym, "#{k}?".to_sym] }
45
+ end
46
+ end
47
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.41.0'
4
+ VERSION = '0.45.1'
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.41.0
4
+ version: 0.45.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: 2020-07-19 00:00:00.000000000 Z
11
+ date: 2020-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -109,6 +109,7 @@ files:
109
109
  - README.rdoc
110
110
  - lib/eac_ruby_utils.rb
111
111
  - lib/eac_ruby_utils/arguments_consumer.rb
112
+ - lib/eac_ruby_utils/boolean.rb
112
113
  - lib/eac_ruby_utils/by_reference.rb
113
114
  - lib/eac_ruby_utils/common_concern.rb
114
115
  - lib/eac_ruby_utils/common_constructor.rb
@@ -139,6 +140,10 @@ files:
139
140
  - lib/eac_ruby_utils/envs/process.rb
140
141
  - lib/eac_ruby_utils/envs/spawn.rb
141
142
  - lib/eac_ruby_utils/envs/ssh_env.rb
143
+ - lib/eac_ruby_utils/envs/ssh_env/dasho_options.rb
144
+ - lib/eac_ruby_utils/envs/ssh_env/identity_file.rb
145
+ - lib/eac_ruby_utils/envs/ssh_env/quiet.rb
146
+ - lib/eac_ruby_utils/envs/ssh_env/terminal.rb
142
147
  - lib/eac_ruby_utils/filesystem_cache.rb
143
148
  - lib/eac_ruby_utils/fs.rb
144
149
  - lib/eac_ruby_utils/fs/extname.rb
@@ -156,6 +161,7 @@ files:
156
161
  - lib/eac_ruby_utils/immutable/common_accessor.rb
157
162
  - lib/eac_ruby_utils/immutable/hash_accessor.rb
158
163
  - lib/eac_ruby_utils/immutable/instance_methods.rb
164
+ - lib/eac_ruby_utils/inflector.rb
159
165
  - lib/eac_ruby_utils/listable.rb
160
166
  - lib/eac_ruby_utils/listable/class_methods.rb
161
167
  - lib/eac_ruby_utils/listable/instance_methods.rb
@@ -187,12 +193,15 @@ files:
187
193
  - lib/eac_ruby_utils/patches/object.rb
188
194
  - lib/eac_ruby_utils/patches/object/asserts.rb
189
195
  - lib/eac_ruby_utils/patches/object/if_present.rb
196
+ - lib/eac_ruby_utils/patches/object/if_respond.rb
190
197
  - lib/eac_ruby_utils/patches/object/template.rb
191
198
  - lib/eac_ruby_utils/patches/object/to_pathname.rb
192
199
  - lib/eac_ruby_utils/patches/pathname.rb
193
200
  - lib/eac_ruby_utils/patches/pathname/basename_sub.rb
194
201
  - lib/eac_ruby_utils/patches/regexp.rb
195
202
  - lib/eac_ruby_utils/patches/regexp/if_match.rb
203
+ - lib/eac_ruby_utils/patches/string.rb
204
+ - lib/eac_ruby_utils/patches/string/inflector.rb
196
205
  - lib/eac_ruby_utils/patches/time.rb
197
206
  - lib/eac_ruby_utils/patches/time/default_time_zone_set.rb
198
207
  - lib/eac_ruby_utils/patches/time/local_time_zone.rb
@@ -206,6 +215,7 @@ files:
206
215
  - lib/eac_ruby_utils/ruby/on_clean_environment.rb
207
216
  - lib/eac_ruby_utils/settings_provider.rb
208
217
  - lib/eac_ruby_utils/simple_cache.rb
218
+ - lib/eac_ruby_utils/struct.rb
209
219
  - lib/eac_ruby_utils/templates.rb
210
220
  - lib/eac_ruby_utils/templates/directory.rb
211
221
  - lib/eac_ruby_utils/templates/file.rb
@@ -237,8 +247,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
237
247
  - !ruby/object:Gem::Version
238
248
  version: '0'
239
249
  requirements: []
240
- rubyforge_project:
241
- rubygems_version: 2.7.7
250
+ rubygems_version: 3.0.8
242
251
  signing_key:
243
252
  specification_version: 4
244
253
  summary: Utilities for E.A.C.'s Ruby projects.