trees 0.3.4 → 0.3.5

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/lib/line.rb +1 -1
  3. data/lib/trees.rb +16 -13
  4. data/lib/version.rb +1 -1
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b21e86099694d3b6b36152f0bfa445d7baa921c4fc1b085c5d2da22fa1d2131e
4
- data.tar.gz: c1320e651491ffca5053b1b04a7e797b7633c2253baad83c22fd9b798d38399a
3
+ metadata.gz: 6ed26c969afc761461ea690075a2c838156cb3309fef5fbac31f219b716c71a8
4
+ data.tar.gz: 47fed5e9edb8a0b5a930ef505beb53381c121dd84cb4d50c89d1b84f6c2875ce
5
5
  SHA512:
6
- metadata.gz: a0d86359f6a0497932b3a628544b744aeecd8ef9b5f376480e056330ea2c8c3694bfbd8e7c8a4e55634e25a3759e4ee2aec7738288fd5d68eb7c21ad7d66cfb5
7
- data.tar.gz: c75011d6796a2c0a8e60061edd75e10b61aaba8649c7755453ae9cba11a2cd2d9267d8e57b494368b32db4d5ac20bba77fcd376098fe9e664e81869d59b26e7a
6
+ metadata.gz: 3142f22906faf7f82aed9b56586c4007bbcda629b7d0c98b4099223854e0469317d39f49b44bd55f8fbf378d167a27e5d850a5210bfb0a7177d0547d1e662fa4
7
+ data.tar.gz: 425cf3ce7982b240e8527a34cb2928c071b588896112f2f02b23b428eb887fd017d26ade1f9502a130e9fcd6ea0ef5f6cca8cdd1493ef9c335ddef7aca98f55d
data/lib/line.rb CHANGED
@@ -5,7 +5,7 @@ module Trees
5
5
  attr_reader :path, :params
6
6
  attr_accessor :summary, :example, :execute
7
7
 
8
- def initialize(path:, params: {})
8
+ def initialize(path:, params: [])
9
9
  @path = path
10
10
  @params = params
11
11
 
data/lib/trees.rb CHANGED
@@ -4,20 +4,18 @@ require_relative 'line'
4
4
  require_relative 'trie'
5
5
 
6
6
  module Trees
7
- attr_reader :lines, :trie
8
-
9
- TOKEN_SEPARATOR = ' '.freeze
7
+ TOKEN_SEPARATOR = ' '
10
8
 
11
9
  def line(path, &block)
12
10
  current_path << path
13
11
  current_path_joined = current_path.join(TOKEN_SEPARATOR)
14
12
 
15
- @current_line = Line.new(path: current_path_joined, params: block.parameters.to_h)
13
+ @current_line = Line.new(path: current_path_joined, params: block.parameters.map(&:last))
16
14
 
17
15
  lines[current_path_joined] = @current_line
18
16
  trie.merge(line: @current_line)
19
17
 
20
- block.call if block_given?
18
+ block.call(**stub_required_keywords(block:)) if block_given?
21
19
 
22
20
  current_path.pop
23
21
  end
@@ -48,19 +46,24 @@ module Trees
48
46
  while results.count > 0
49
47
  result = results.pop
50
48
 
51
- if result.line.execute
52
- result.line.params.values.each do |param|
53
- result.line.execute.binding.local_variable_set(param, result.params[param])
54
- end
55
-
56
- result.line.execute.call
49
+ next unless result.line.execute
57
50
 
58
- return true
51
+ result.line.params.each do |param|
52
+ result.line.execute.binding.local_variable_set(param, result.params[param]) if result.params.key?(param)
59
53
  end
54
+
55
+ result.line.execute.call
56
+
57
+ return true
60
58
  end
61
59
 
62
60
  false
63
- end
61
+ end
62
+
63
+ # The "line" block defines the params that the "execute" child block will use later but doesn't itself execute user input.
64
+ def stub_required_keywords(block:)
65
+ block.parameters.filter_map { |type, name| [name, nil] if type == :keyreq }.to_h
66
+ end
64
67
 
65
68
  def current_path
66
69
  @current_path ||= []
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Trees
4
- VERSION = '0.3.4'
4
+ VERSION = '0.3.5'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trees
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - maedi