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
@@ -1,21 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_support/core_ext/object'
4
- require 'eac_ruby_utils/patches/object/asserts'
3
+ require 'eac_ruby_utils/core_ext'
5
4
 
6
5
  module EacRubyUtils
7
6
  class PathsHash
7
+ require_sub __FILE__
8
+
8
9
  class << self
9
10
  def parse_entry_key(entry_key)
10
11
  r = entry_key.to_s.strip
11
- raise EntryKeyError, 'Entry key cannot start or end with dot' if
12
+ raise ::EacRubyUtils::PathsHash::EntryKeyError, 'Entry key cannot start or end with dot' if
12
13
  r.start_with?('.') || r.end_with?('.')
13
14
 
14
15
  r = r.split('.').map(&:strip)
15
- raise EntryKeyError, "Entry key \"#{entry_key}\" is empty" if r.empty?
16
+ if r.empty?
17
+ raise ::EacRubyUtils::PathsHash::EntryKeyError, "Entry key \"#{entry_key}\" is empty"
18
+ end
16
19
  return r.map(&:to_sym) unless r.any?(&:blank?)
17
20
 
18
- raise EntryKeyError, "Entry key \"#{entry_key}\" has at least one blank part"
21
+ raise ::EacRubyUtils::PathsHash::EntryKeyError,
22
+ "Entry key \"#{entry_key}\" has at least one blank part"
19
23
  end
20
24
  end
21
25
 
@@ -26,68 +30,27 @@ module EacRubyUtils
26
30
  end
27
31
 
28
32
  def [](entry_key)
29
- root.read_entry(self.class.parse_entry_key(entry_key), [])
33
+ root.read_entry(::EacRubyUtils::PathsHash::PathSearch.parse_entry_key(entry_key))
30
34
  end
31
35
 
32
36
  def []=(entry_key, entry_value)
33
- root.write_entry(self.class.parse_entry_key(entry_key), entry_value, [])
37
+ root.write_entry(
38
+ ::EacRubyUtils::PathsHash::PathSearch.parse_entry_key(entry_key), entry_value
39
+ )
34
40
  end
35
41
 
36
- delegate :to_h, to: :root
37
-
38
- private
39
-
40
- attr_reader :data
41
-
42
- class EntryKeyError < StandardError
42
+ def fetch(entry_key)
43
+ root.fetch(::EacRubyUtils::PathsHash::PathSearch.parse_entry_key(entry_key))
43
44
  end
44
45
 
45
- class Node
46
- def initialize(source_hash)
47
- source_hash.assert_argument(Hash, 'source_hash')
48
- @data = source_hash.map { |k, v| [k.to_sym, v.is_a?(Hash) ? Node.new(v) : v] }.to_h
49
- end
50
-
51
- def to_h
52
- data.map { |k, v| [k, v.is_a?(Node) ? v.to_h : v] }.to_h
53
- end
54
-
55
- def read_entry(path, current)
56
- validate_path(path, current)
57
- node_key = path.shift
58
- node = data[node_key]
59
- return (node.is_a?(Node) ? node.to_h : node) if path.empty?
60
- return nil if node.blank?
61
- return node.read_entry(path, current + [node_key]) if node.is_a?(Node)
62
-
63
- raise(EntryKeyError,
64
- "Path #{current.join(',')} is not a Node and path continues (#{current + path})")
65
- end
66
-
67
- def write_entry(path, value, current)
68
- validate_path(path, current)
69
- node_key = path.shift
70
- write_entry_value(path, node_key, value, current)
71
- end
72
-
73
- private
46
+ def key?(entry_key)
47
+ root.entry?(::EacRubyUtils::PathsHash::PathSearch.parse_entry_key(entry_key))
48
+ end
74
49
 
75
- def write_entry_value(path, node_key, value, current)
76
- if path.empty?
77
- data[node_key] = value.is_a?(Hash) ? Node.new(value) : value
78
- else
79
- data[node_key] = Node.new({}) unless data[node_key].is_a?(Node)
80
- data[node_key].write_entry(path, value, current + [node_key])
81
- end
82
- end
50
+ delegate :to_h, to: :root
83
51
 
84
- def validate_path(path, current)
85
- path.assert_argument(Array, 'path')
86
- current.assert_argument(Array, 'current')
87
- raise EntryKeyError, 'Path is empty' if path.empty?
88
- end
52
+ private
89
53
 
90
- attr_reader :data
91
- end
54
+ attr_reader :data
92
55
  end
93
56
  end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacRubyUtils
4
+ class PathsHash
5
+ class EntryKeyError < StandardError
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/paths_hash/entry_key_error'
5
+
6
+ module EacRubyUtils
7
+ class PathsHash
8
+ class Node
9
+ PATH_SEARCH_UNENDED_ERROR_MESSAGE = 'Path search is not a Node and is not ended'
10
+
11
+ def initialize(source_hash)
12
+ source_hash.assert_argument(Hash, 'source_hash')
13
+ @data = source_hash.map { |k, v| [k.to_sym, v.is_a?(Hash) ? Node.new(v) : v] }.to_h
14
+ end
15
+
16
+ def entry?(path_search)
17
+ return false unless data.key?(path_search.cursor)
18
+ return true if path_search.ended?
19
+ return data.fetch(path_search.cursor).entry?(path_search.succeeding) if
20
+ data.fetch(path_search.cursor).is_a?(Node)
21
+
22
+ false # Paths continue and there is not available nodes
23
+ end
24
+
25
+ def fetch(path_search)
26
+ if data.key?(path_search.cursor)
27
+ node = data.fetch(path_search.cursor)
28
+ return (node.is_a?(Node) ? node.to_h : node) if path_search.ended?
29
+ return nil if node.blank?
30
+ return node.fetch(path_search.succeeding) if node.is_a?(Node)
31
+ end
32
+
33
+ path_search.raise_error(PATH_SEARCH_UNENDED_ERROR_MESSAGE)
34
+ end
35
+
36
+ def to_h
37
+ data.map { |k, v| [k, v.is_a?(Node) ? v.to_h : v] }.to_h
38
+ end
39
+
40
+ def read_entry(path_search)
41
+ node = data[path_search.cursor]
42
+ return (node.is_a?(Node) ? node.to_h : node) if path_search.ended?
43
+ return nil if node.blank?
44
+ return node.read_entry(path_search.succeeding) if node.is_a?(Node)
45
+
46
+ path_search.raise_error(PATH_SEARCH_UNENDED_ERROR_MESSAGE)
47
+ end
48
+
49
+ def write_entry(path_search, value)
50
+ if path_search.ended?
51
+ data[path_search.cursor] = value.is_a?(Hash) ? self.class.new(value) : value
52
+ else
53
+ assert_data_node(path_search.cursor).write_entry(path_search.succeeding, value)
54
+ end
55
+ end
56
+
57
+ private
58
+
59
+ attr_reader :data
60
+
61
+ def assert_data_node(key)
62
+ data[key] = self.class.new({}) unless data[key].is_a?(Node)
63
+ data[key]
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacRubyUtils
4
+ class PathsHash
5
+ class PathSearch
6
+ class << self
7
+ def parse_entry_key(string)
8
+ new(::EacRubyUtils::PathsHash.parse_entry_key(string), [])
9
+ end
10
+ end
11
+
12
+ common_constructor :current, :previous do
13
+ self.current = current.assert_argument(Array, 'current').freeze
14
+ self.previous = previous.assert_argument(Array, 'previous')
15
+ raise ::EacRubyUtils::PathsHash::EntryKeyError, 'Current is empty' if current.empty?
16
+ end
17
+
18
+ def cursor
19
+ current.first
20
+ end
21
+
22
+ def ended?
23
+ current.count <= 1
24
+ end
25
+
26
+ def raise_error(message)
27
+ raise ::EacRubyUtils::PathsHash::EntryKeyError, "#{message} (#{self})"
28
+ end
29
+
30
+ def succeeding
31
+ self.class.new(current[1..-1], previous + [cursor])
32
+ end
33
+
34
+ def to_s
35
+ "#{self.class}[Current: #{current}, Previous: #{previous}]"
36
+ end
37
+ end
38
+ end
39
+ 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)
@@ -8,7 +8,8 @@ module EacRubyUtils
8
8
  # A [EacRubyUtils::Envs::Command] which runs in a clean Ruby environment.
9
9
  class Command < ::EacRubyUtils::Envs::Command
10
10
  def initialize(bundle_args, extra_options = {})
11
- super(::EacRubyUtils::Envs.local, bundle_args, extra_options)
11
+ host_env = extra_options.delete(:host_env)
12
+ super(host_env || ::EacRubyUtils::Envs.local, bundle_args, extra_options)
12
13
  end
13
14
 
14
15
  %w[system execute].each do |method_prefix|
@@ -21,8 +21,12 @@ module EacRubyUtils
21
21
  end
22
22
  end
23
23
 
24
- def reset_cache
25
- @cache_keys = nil
24
+ def reset_cache(*keys)
25
+ if keys.any?
26
+ keys.each { |key| cache_keys.delete(key) }
27
+ else
28
+ @cache_keys = nil
29
+ end
26
30
  end
27
31
 
28
32
  private
@@ -0,0 +1,57 @@
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
+ def slice_fetch(*keys)
31
+ self.class.new(keys.map { |key| [key, fetch(key)] }.to_h)
32
+ end
33
+
34
+ def to_h
35
+ data.dup
36
+ end
37
+
38
+ delegate :to_s, to: :data
39
+
40
+ private
41
+
42
+ attr_accessor :data
43
+
44
+ def parse_key(key)
45
+ m = /\A(.+)\?\z/.match(key.to_s)
46
+ [(m ? m[1] : key.to_s).to_sym, m ? true : false]
47
+ end
48
+
49
+ def property_method?(key)
50
+ property_methods.include?(key.to_sym)
51
+ end
52
+
53
+ def property_methods
54
+ data.keys.flat_map { |k| [k.to_sym, "#{k}?".to_sym] }
55
+ end
56
+ end
57
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.40.0'
4
+ VERSION = '0.50.0'
5
5
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/blank_not_blank'
4
+
5
+ RSpec.describe ::EacRubyUtils::BlankNotBlank do
6
+ let(:instance) { described_class.instance }
7
+
8
+ it do
9
+ expect { described_class.new }.to raise_error(::NoMethodError)
10
+ end
11
+
12
+ it { expect(instance).to be_present }
13
+ it { expect(instance).not_to be_blank }
14
+ it { expect(instance).to be_truthy }
15
+ it { expect(instance).to eq('') }
16
+ end
@@ -28,4 +28,19 @@ RSpec.describe ::EacRubyUtils::Configs do
28
28
 
29
29
  it { expect(::YAML.load_file(storage_path)).to eq(parent: { child: 'value1' }) }
30
30
  end
31
+
32
+ describe '#read' do
33
+ let(:present_key) { 'a.present.key' }
34
+ let(:blank_key) { 'a.blank.key' }
35
+
36
+ before do
37
+ instance[present_key] = 'A value'
38
+ instance[blank_key] = ''
39
+ instance.save
40
+ instance.load
41
+ end
42
+
43
+ it { expect(instance[present_key]).to be_present }
44
+ it { expect(instance[blank_key]).to be_present }
45
+ end
31
46
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/inflector'
4
+
5
+ RSpec.describe ::EacRubyUtils::Inflector do
6
+ describe '#variableize' do
7
+ {
8
+ '_A_variableName' => 'a_variablename'
9
+ }.each do |source, expected|
10
+ context "when source is \"#{source}\"" do
11
+ it { expect(described_class.variableize(source)).to eq(expected) }
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/patches/enumerator/current'
4
+
5
+ RSpec.describe ::Enumerator do
6
+ let(:list) { %w[a b] }
7
+ let(:instance) { list.each }
8
+
9
+ it { expect(instance).to be_a(described_class) }
10
+ it { expect(instance.current).to eq('a') }
11
+
12
+ context 'with first next' do
13
+ before { instance.next }
14
+
15
+ it { expect(instance.current).to eq('b') }
16
+ end
17
+
18
+ context 'with last next' do
19
+ before do
20
+ instance.next
21
+ instance.next
22
+ end
23
+
24
+ it { expect(instance.current).to eq(nil) }
25
+ end
26
+ end