ehbrs-tools 0.13.0 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ehbrs/executables.rb +1 -1
  3. data/lib/ehbrs/runner.rb +10 -17
  4. data/lib/ehbrs/runner/finances.rb +4 -7
  5. data/lib/ehbrs/runner/finances/bb_browser.rb +5 -10
  6. data/lib/ehbrs/runner/fs.rb +4 -7
  7. data/lib/ehbrs/runner/fs/used_space.rb +8 -9
  8. data/lib/ehbrs/runner/google.rb +4 -7
  9. data/lib/ehbrs/runner/google/translate.rb +7 -12
  10. data/lib/ehbrs/runner/self.rb +4 -7
  11. data/lib/ehbrs/runner/self/test.rb +5 -10
  12. data/lib/ehbrs/runner/vg.rb +4 -7
  13. data/lib/ehbrs/runner/vg/ips.rb +9 -14
  14. data/lib/ehbrs/runner/vg/wii.rb +10 -13
  15. data/lib/ehbrs/runner/videos.rb +7 -14
  16. data/lib/ehbrs/runner/videos/extract.rb +10 -13
  17. data/lib/ehbrs/runner/videos/probe.rb +32 -0
  18. data/lib/ehbrs/runner/videos/series.rb +5 -8
  19. data/lib/ehbrs/runner/videos/series/rename.rb +9 -12
  20. data/lib/ehbrs/runner/videos/unsupported.rb +9 -13
  21. data/lib/ehbrs/runner/web_utils.rb +24 -0
  22. data/lib/ehbrs/runner/web_utils/videos.rb +18 -0
  23. data/lib/ehbrs/runner/web_utils/videos/download.rb +63 -0
  24. data/lib/ehbrs/runner/web_utils/videos/upload.rb +75 -0
  25. data/lib/ehbrs/tools/version.rb +1 -1
  26. data/lib/ehbrs/videos/file.rb +2 -1
  27. data/lib/ehbrs/videos/series/rename/file/options.rb +3 -13
  28. data/lib/ehbrs/videos/unsupported/fix_profile.rb +1 -0
  29. data/vendor/eac_cli/eac_cli.gemspec +3 -3
  30. data/vendor/eac_cli/lib/eac_cli/core_ext.rb +4 -0
  31. data/vendor/eac_cli/lib/eac_cli/default_runner.rb +6 -14
  32. data/vendor/eac_cli/lib/eac_cli/definition.rb +94 -0
  33. data/vendor/eac_cli/lib/eac_cli/definition/argument_option.rb +13 -0
  34. data/vendor/eac_cli/lib/eac_cli/definition/base_option.rb +42 -0
  35. data/vendor/eac_cli/lib/eac_cli/definition/boolean_option.rb +13 -0
  36. data/vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb +31 -0
  37. data/vendor/eac_cli/lib/eac_cli/{runner/docopt_doc.rb → docopt/doc_builder.rb} +15 -8
  38. data/vendor/eac_cli/lib/eac_cli/docopt/runner_extension.rb +46 -0
  39. data/vendor/eac_cli/lib/eac_cli/parser.rb +14 -0
  40. data/vendor/eac_cli/lib/eac_cli/parser/collector.rb +60 -0
  41. data/vendor/eac_cli/lib/eac_cli/parser/error.rb +15 -0
  42. data/vendor/eac_cli/lib/eac_cli/parser/options_collection.rb +127 -0
  43. data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +38 -0
  44. data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +77 -0
  45. data/vendor/eac_cli/lib/eac_cli/patches.rb +4 -0
  46. data/vendor/eac_cli/lib/eac_cli/patches/object.rb +5 -0
  47. data/vendor/eac_cli/lib/eac_cli/patches/object/runner_with.rb +25 -0
  48. data/vendor/eac_cli/lib/eac_cli/runner.rb +68 -7
  49. data/vendor/eac_cli/lib/eac_cli/runner/context.rb +35 -0
  50. data/vendor/eac_cli/lib/eac_cli/runner_with.rb +9 -0
  51. data/vendor/eac_cli/lib/eac_cli/runner_with/help.rb +19 -0
  52. data/vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb +26 -0
  53. data/vendor/eac_cli/lib/eac_cli/runner_with/subcommands.rb +96 -0
  54. data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
  55. data/vendor/eac_cli/spec/lib/eac_cli/docopt/runner_extension_spec.rb +25 -0
  56. data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +78 -0
  57. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +57 -0
  58. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/blank_not_blank.rb +19 -0
  59. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb +31 -0
  60. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb +4 -4
  61. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/base.rb +43 -0
  62. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/file.rb +12 -31
  63. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +8 -40
  64. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/read_entry_options.rb +41 -0
  65. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner.rb +6 -0
  66. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_class_methods.rb +2 -2
  67. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_subcommands.rb +8 -2
  68. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env.rb +12 -9
  69. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/dasho_options.rb +53 -0
  70. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/identity_file.rb +25 -0
  71. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/quiet.rb +24 -0
  72. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/terminal.rb +34 -0
  73. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/clearable_directory.rb +57 -0
  74. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/array_accessor.rb +4 -0
  75. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/hash_accessor.rb +4 -0
  76. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb +18 -0
  77. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/list.rb +5 -0
  78. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/value.rb +3 -2
  79. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator.rb +4 -0
  80. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/current.rb +9 -0
  81. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/stopped.rb +14 -0
  82. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_respond.rb +22 -0
  83. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/string.rb +4 -0
  84. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/string/inflector.rb +9 -0
  85. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash.rb +21 -58
  86. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/entry_key_error.rb +8 -0
  87. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/node.rb +67 -0
  88. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/path_search.rb +39 -0
  89. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/require_sub.rb +8 -8
  90. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/ruby/command.rb +2 -1
  91. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/simple_cache.rb +6 -2
  92. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/struct.rb +57 -0
  93. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  94. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/blank_not_blank_spec.rb +16 -0
  95. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/configs_spec.rb +15 -0
  96. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/inflector_spec.rb +15 -0
  97. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/current_spec.rb +26 -0
  98. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/stopped_spec.rb +32 -0
  99. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb +52 -13
  100. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/struct_spec.rb +46 -0
  101. data/vendor/ehbrs_ruby_utils/Gemfile +16 -0
  102. data/vendor/ehbrs_ruby_utils/ehbrs_ruby_utils.gemspec +20 -0
  103. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils.rb +7 -0
  104. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/executables.rb +28 -0
  105. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/version.rb +5 -0
  106. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos.rb +9 -0
  107. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container.rb +11 -0
  108. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/file.rb +31 -0
  109. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/info.rb +21 -0
  110. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/quality.rb +68 -0
  111. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/resolution.rb +68 -0
  112. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils.rb +9 -0
  113. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/instance.rb +32 -0
  114. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos.rb +11 -0
  115. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos/file.rb +40 -0
  116. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos/files_list.rb +76 -0
  117. data/vendor/ehbrs_ruby_utils/spec/lib/ehbrs_ruby_utils/videos/resolution_spec.rb +18 -0
  118. data/vendor/ehbrs_ruby_utils/spec/rubocop_check_spec.rb +7 -0
  119. data/vendor/ehbrs_ruby_utils/spec/spec_helper.rb +100 -0
  120. metadata +77 -10
  121. data/vendor/eac_cli/lib/eac_cli/runner/argument_option.rb +0 -13
  122. data/vendor/eac_cli/lib/eac_cli/runner/base_option.rb +0 -22
  123. data/vendor/eac_cli/lib/eac_cli/runner/boolean_option.rb +0 -13
  124. data/vendor/eac_cli/lib/eac_cli/runner/definition.rb +0 -64
  125. data/vendor/eac_cli/lib/eac_cli/runner/positional_argument.rb +0 -23
@@ -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
@@ -2,12 +2,16 @@
2
2
 
3
3
  require 'addressable'
4
4
  require 'eac_ruby_utils/envs/base_env'
5
+ require 'eac_ruby_utils/patches/object/if_present'
6
+ require 'eac_ruby_utils/patches/module/require_sub'
5
7
  require 'net/ssh'
6
8
  require 'shellwords'
7
9
 
8
10
  module EacRubyUtils
9
11
  module Envs
10
12
  class SshEnv < ::EacRubyUtils::Envs::BaseEnv
13
+ require_sub __FILE__, include_modules: true
14
+
11
15
  USER_PATTERN = /[a-z_][a-z0-9_-]*/.freeze
12
16
  HOSTNAME_PATTERN = /[^@]+/.freeze
13
17
  USER_HOSTNAME_PATTERN = /\A(?:(#{USER_PATTERN})@)?(#{HOSTNAME_PATTERN})\z/.freeze
@@ -49,17 +53,16 @@ module EacRubyUtils
49
53
  private
50
54
 
51
55
  def ssh_command_line
52
- r = %w[ssh]
53
- r += ['-p', uri.port] if uri.port.present?
54
- r += ssh_command_line_options
55
- r << user_hostname_uri
56
- 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(' ')
57
60
  end
58
61
 
59
- def ssh_command_line_options
60
- r = []
61
- uri.query_values&.each { |k, v| r += ['-o', "#{k}=#{v}"] }
62
- r
62
+ def ssh_command_line_port_args
63
+ uri.port.if_present([]) do |v|
64
+ ['-p', v]
65
+ end
63
66
  end
64
67
 
65
68
  def user_hostname_uri
@@ -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,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fileutils'
4
+ require 'pathname'
5
+
6
+ module EacRubyUtils
7
+ module Fs
8
+ class ClearableDirectory < ::Pathname
9
+ CLEARABLE_BASENAME = '.clearable_directory'
10
+
11
+ def clear
12
+ validate_clearable
13
+ directory? ? clear_directory : clear_no_directory
14
+ mkpath
15
+ ::FileUtils.touch(clearable_note_file.to_path)
16
+ self
17
+ end
18
+
19
+ def clearable?
20
+ clearable_negate_message ? true : false
21
+ end
22
+
23
+ def clearable_negate_message
24
+ return if !exist? || empty?
25
+ return "Path \"#{self}\" exists, is not empty and is not a directory" unless directory?
26
+ return if clearable_note_file.exist?
27
+
28
+ "Directory \"#{self}\" is not empty and does not have a #{CLEARABLE_BASENAME} file"
29
+ end
30
+
31
+ def clearable_note_file
32
+ join(CLEARABLE_BASENAME)
33
+ end
34
+
35
+ def validate_clearable
36
+ message = clearable_negate_message
37
+ raise message if message
38
+ end
39
+
40
+ private
41
+
42
+ def clear_directory
43
+ children.each do |child|
44
+ if child.directory?
45
+ child.rmtree
46
+ elsif child.file?
47
+ child.unlink
48
+ end
49
+ end
50
+ end
51
+
52
+ def clear_no_directory
53
+ ::FileUtils.rm_rf(to_path)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -18,6 +18,10 @@ module EacRubyUtils
18
18
  end
19
19
  end
20
20
 
21
+ def immutable_value_get(object)
22
+ super || []
23
+ end
24
+
21
25
  def immutable_value_set(object, value)
22
26
  duplicate_object(object) do |old_value|
23
27
  (old_value || []) + [value]
@@ -11,6 +11,10 @@ module EacRubyUtils
11
11
  apply_set(klass)
12
12
  end
13
13
 
14
+ def immutable_value_get(object)
15
+ super || {}
16
+ end
17
+
14
18
  def immutable_value_set(object, key, value)
15
19
  duplicate_object(object) do |old_value|
16
20
  (old_value || {}).merge(key => value)
@@ -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,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
+ class Enumerator
4
+ def current(default_value = nil)
5
+ peek
6
+ rescue ::StopIteration
7
+ default_value
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Enumerator
4
+ def ongoing?
5
+ !stopped?
6
+ end
7
+
8
+ def stopped?
9
+ peek
10
+ false
11
+ rescue ::StopIteration
12
+ true
13
+ end
14
+ end
@@ -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