na 1.2.80 → 1.2.81

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.
data/lib/na/hash.rb CHANGED
@@ -1,15 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ::Hash
4
+ # Convert all keys in the hash to symbols recursively
5
+ #
6
+ # @return [Hash] Hash with symbolized keys
4
7
  def symbolize_keys
5
8
  each_with_object({}) { |(k, v), hsh| hsh[k.to_sym] = v.is_a?(Hash) ? v.symbolize_keys : v }
6
9
  end
7
10
 
8
- ##
9
- ## Freeze all values in a hash
10
- ##
11
- ## @return Hash with all values frozen
12
- ##
11
+ #
12
+ # Freeze all values in a hash
13
+ #
14
+ # @return Hash with all values frozen
13
15
  def deep_freeze
14
16
  chilled = {}
15
17
  each do |k, v|
@@ -19,10 +21,16 @@ class ::Hash
19
21
  chilled.freeze
20
22
  end
21
23
 
24
+ # Freeze all values in a hash in place
25
+ #
26
+ # @return [Hash] Hash with all values frozen
22
27
  def deep_freeze!
23
28
  replace deep_thaw.deep_freeze
24
29
  end
25
30
 
31
+ # Recursively duplicate all values in a hash
32
+ #
33
+ # @return [Hash] Hash with all values duplicated
26
34
  def deep_thaw
27
35
  chilled = {}
28
36
  each do |k, v|
@@ -32,12 +40,27 @@ class ::Hash
32
40
  chilled.dup
33
41
  end
34
42
 
43
+ # Recursively duplicate all values in a hash in place
44
+ #
45
+ # @return [Hash] Hash with all values duplicated
35
46
  def deep_thaw!
36
47
  replace deep_thaw
37
48
  end
38
49
 
39
- def deep_merge(second)
40
- merger = proc { |_, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : Array === v1 && Array === v2 ? v1 | v2 : [:undefined, nil, :nil].include?(v2) ? v1 : v2 }
41
- merge(second.to_h, &merger)
42
- end
50
+ # Recursively merge two hashes, combining arrays and preferring non-nil values
51
+ #
52
+ # @param second [Hash] The hash to merge with
53
+ # @return [Hash] The merged hash
54
+ def deep_merge(second)
55
+ merger = proc { |_, v1, v2|
56
+ if v1.is_a?(Hash) && v2.is_a?(Hash)
57
+ v1.merge(v2, &merger)
58
+ elsif v1.is_a?(Array) && v2.is_a?(Array)
59
+ v1 | v2
60
+ else
61
+ [:undefined, nil, :nil].include?(v2) ? v1 : v2
62
+ end
63
+ }
64
+ merge(second.to_h, &merger)
65
+ end
43
66
  end
@@ -4,7 +4,15 @@ module GLI
4
4
  module Commands
5
5
  # Help Command Monkeypatch for paginated output
6
6
  class Help < Command
7
- def show_help(global_options, options, arguments, out, error)
7
+ # Show help output for GLI commands with paginated output
8
+ #
9
+ # @param global_options [Hash] Global CLI options
10
+ # @param options [Hash] Command-specific options
11
+ # @param arguments [Array] Command arguments
12
+ # @param out [IO] Output stream
13
+ # @param error [IO] Error stream
14
+ # @return [void]
15
+ def show_help(_global_options, options, arguments, out, error)
8
16
  NA::Pager.paginate = true
9
17
 
10
18
  command_finder = HelpModules::CommandFinder.new(@app, arguments, error)