node_query 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 937481646456841ca565042544794aa91a0339c40790f14233d721f45b0531fa
4
- data.tar.gz: 807b2709a6350489229a86febb0d6d7eb9684f8ce4fb712603d6bcd6cb62f192
3
+ metadata.gz: 6e8376d63c29cbdec1d39e74083667724b0b84e872d7a26fc281b18061e82f02
4
+ data.tar.gz: '078fc70a86d2bfca404c791c6f9466780daca529aca5e984aca4ecdc6fb4c760'
5
5
  SHA512:
6
- metadata.gz: 9bff7b923a263ad1817226f7fbb095cb9275b1f0e6f27dadd5562202c04aa2ba7bebb0c5b4659484dfeafc5adff268a7f8cd09e7c1f628b17d9c638fbc280c41
7
- data.tar.gz: 102c406278c8b752c6ead8856247678f79a5ca2fb178f625a746030c330f9310a6f3d4decdb860a12cad8ae95982d014b102704c5afe60edfe95c066ad26dc3f
6
+ metadata.gz: 444e804e949a7ebd40ebc10312de06bd570115995044598fe324210a60e85fd90931393f0eaa6845ec46c916101ab69e23ccd9490ffa40c99626ecc96c0acfb1
7
+ data.tar.gz: e0c5ab049ddc1f608b6559b186bd9f43b16b4d6a6b8ed906bcf261cebdb18a482768673727644797dc8f29465d423fc3148c722db001904439d1890cd80541db
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.2.0 (2022-07-01)
4
+
5
+ * Rename `NodeQuery.get_adapter` to `NodeQuery.adapter`
6
+ * Use generic type in rbs
7
+ * Fix `Compiler::Array` to `Compiler::ArrayValue`
8
+
3
9
  ## 1.1.0 (2022-06-27)
4
10
 
5
11
  * Support `*` in attribute key
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- node_query (1.1.0)
4
+ node_query (1.2.0)
5
5
  activesupport
6
6
 
7
7
  GEM
@@ -50,7 +50,7 @@ GEM
50
50
  oedipus_lex (2.6.0)
51
51
  parser (3.1.2.0)
52
52
  ast (~> 2.4.1)
53
- parser_node_ext (0.1.0)
53
+ parser_node_ext (0.2.0)
54
54
  parser
55
55
  pry (0.14.1)
56
56
  coderay (~> 1.1)
@@ -17,7 +17,7 @@ module NodeQuery::Compiler
17
17
  def match?(node, _operator = '==')
18
18
  return false unless node
19
19
 
20
- @node_type.to_sym == NodeQuery.get_adapter.get_node_type(node) && (!@attribute_list || @attribute_list.match?(node))
20
+ @node_type.to_sym == NodeQuery.adapter.get_node_type(node) && (!@attribute_list || @attribute_list.match?(node))
21
21
  end
22
22
 
23
23
  def to_s
@@ -75,9 +75,9 @@ module NodeQuery::Compiler
75
75
  # @return the node value, could be integer, float, string, boolean, nil, range, and etc.
76
76
  def actual_value(node)
77
77
  if node.is_a?(::Parser::AST::Node)
78
- case NodeQuery.get_adapter.get_node_type(node)
78
+ case NodeQuery.adapter.get_node_type(node)
79
79
  when :int, :float, :str, :sym
80
- NodeQuery.get_adapter.get_children(node).last
80
+ NodeQuery.adapter.get_children(node).last
81
81
  when :true
82
82
  true
83
83
  when :false
@@ -85,13 +85,13 @@ module NodeQuery::Compiler
85
85
  when :nil
86
86
  nil
87
87
  when :array
88
- NodeQuery.get_adapter.get_children(node).map { |child_node| actual_value(child_node) }
88
+ NodeQuery.adapter.get_children(node).map { |child_node| actual_value(child_node) }
89
89
  when :irange
90
- actual_value(NodeQuery.get_adapter.get_children(node).first)..actual_value(NodeQuery.get_adapter.get_children(node).last)
90
+ actual_value(NodeQuery.adapter.get_children(node).first)..actual_value(NodeQuery.adapter.get_children(node).last)
91
91
  when :erange
92
- actual_value(NodeQuery.get_adapter.get_children(node).first)...actual_value(NodeQuery.get_adapter.get_children(node).last)
92
+ actual_value(NodeQuery.adapter.get_children(node).first)...actual_value(NodeQuery.adapter.get_children(node).last)
93
93
  when :begin
94
- actual_value(NodeQuery.get_adapter.get_children(node).first)
94
+ actual_value(NodeQuery.adapter.get_children(node).first)
95
95
  else
96
96
  node
97
97
  end
@@ -20,7 +20,7 @@ module NodeQuery::Compiler
20
20
  # @return [String] if node is a {Node}, return the node source code, otherwise return the node itself.
21
21
  def actual_value(node)
22
22
  if node.is_a?(::Parser::AST::Node)
23
- NodeQuery.get_adapter.get_source(node)
23
+ NodeQuery.adapter.get_source(node)
24
24
  else
25
25
  node
26
26
  end
@@ -31,7 +31,7 @@ module NodeQuery::Compiler
31
31
  def expected_value
32
32
  node = NodeQuery::Helper.get_target_node(base_node, @value)
33
33
  if node.is_a?(::Parser::AST::Node)
34
- NodeQuery.get_adapter.get_source(node)
34
+ NodeQuery.adapter.get_source(node)
35
35
  else
36
36
  node
37
37
  end
@@ -20,7 +20,7 @@ module NodeQuery::Compiler
20
20
  # otherwise, return the String value.
21
21
  def actual_value(node)
22
22
  if node.is_a?(::Parser::AST::Node)
23
- NodeQuery.get_adapter.get_source(node)
23
+ NodeQuery.adapter.get_source(node)
24
24
  elsif node.is_a?(::Array)
25
25
  node.map { |n| actual_value(n) }
26
26
  else
@@ -18,7 +18,7 @@ module NodeQuery::Compiler
18
18
  def match?(node, operator = '=~')
19
19
  match =
20
20
  if node.is_a?(::Parser::AST::Node)
21
- @value.match(NodeQuery.get_adapter.get_source(node))
21
+ @value.match(NodeQuery.adapter.get_source(node))
22
22
  else
23
23
  @value.match(node.to_s)
24
24
  end
@@ -30,8 +30,8 @@ class NodeQuery::Helper
30
30
  # @yield [child] Gives a child node.
31
31
  # @yieldparam child [Parser::AST::Node] child node
32
32
  def self.handle_recursive_child(node, &block)
33
- NodeQuery.get_adapter.get_children(node).each do |child|
34
- if NodeQuery.get_adapter.is_node?(child)
33
+ NodeQuery.adapter.get_children(node).each do |child|
34
+ if NodeQuery.adapter.is_node?(child)
35
35
  block.call(child)
36
36
  handle_recursive_child(child, &block)
37
37
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class NodeQuery
4
- VERSION = "1.1.0"
4
+ VERSION = "1.2.0"
5
5
  end
data/lib/node_query.rb CHANGED
@@ -3,13 +3,15 @@
3
3
  require 'active_support/core_ext/array'
4
4
 
5
5
  require_relative "node_query/version"
6
- require_relative "node_query/parser_adapter"
7
- require_relative "node_query/compiler"
8
- require_relative "node_query/helper"
9
6
  require_relative "./node_query_lexer.rex"
10
7
  require_relative "./node_query_parser.racc"
11
8
 
12
9
  class NodeQuery
10
+ autoload :Adapter, "node_query/adapter"
11
+ autoload :ParserAdapter, "node_query/parser_adapter"
12
+ autoload :Compiler, "node_query/compiler"
13
+ autoload :Helper, "node_query/helper"
14
+
13
15
  # Configure NodeQuery
14
16
  # @param [Hash] options options to configure
15
17
  # @option options [NodeQuery::Adapter] :adapter the adpater
@@ -19,7 +21,7 @@ class NodeQuery
19
21
 
20
22
  # Get the adapter
21
23
  # @return [NodeQuery::Adapter] current adapter, by default is {NodeQuery::ParserAdapter}
22
- def self.get_adapter
24
+ def self.adapter
23
25
  @adapter ||= ParserAdapter.new
24
26
  end
25
27
 
@@ -249,7 +249,7 @@ def _reduce_13(val, _values)
249
249
  end
250
250
 
251
251
  def _reduce_14(val, _values)
252
- NodeQuery::Compiler::Attribute.new(key: val[0], value: NodeQuery::Compiler::Array.new, operator: val[1])
252
+ NodeQuery::Compiler::Attribute.new(key: val[0], value: NodeQuery::Compiler::ArrayValue.new, operator: val[1])
253
253
  end
254
254
 
255
255
  def _reduce_15(val, _values)
@@ -28,7 +28,7 @@ rule
28
28
 
29
29
  attribute
30
30
  : tKEY tOPERATOR value { NodeQuery::Compiler::Attribute.new(key: val[0], value: val[2], operator: val[1]) }
31
- | tKEY tOPERATOR tOPEN_ARRAY tCLOSE_ARRAY { NodeQuery::Compiler::Attribute.new(key: val[0], value: NodeQuery::Compiler::Array.new, operator: val[1]) }
31
+ | tKEY tOPERATOR tOPEN_ARRAY tCLOSE_ARRAY { NodeQuery::Compiler::Attribute.new(key: val[0], value: NodeQuery::Compiler::ArrayValue.new, operator: val[1]) }
32
32
  | tKEY tOPERATOR tOPEN_ARRAY array_value tCLOSE_ARRAY { NodeQuery::Compiler::Attribute.new(key: val[0], value: val[3], operator: val[1]) }
33
33
 
34
34
  array_value
@@ -60,4 +60,4 @@ end
60
60
 
61
61
  def next_token
62
62
  @lexer.next_token
63
- end
63
+ end
@@ -1,11 +1,11 @@
1
- class NodeQuery::Adapter
2
- def is_node?: (node: Node) -> Boolean
1
+ class NodeQuery::Adapter[T]
2
+ def is_node?: (node: T) -> bool
3
3
 
4
- def get_node_type: (node: Node) -> String
4
+ def get_node_type: (node: T) -> String
5
5
 
6
- def get_source: (node: Node) -> String
6
+ def get_source: (node: T) -> String
7
7
 
8
- def get_children: (node: Node) -> Array[Node]
8
+ def get_children: (node: T) -> Array[T]
9
9
 
10
- def get_siblings: (node: Node) -> Array[Node]
10
+ def get_siblings: (node: T) -> Array[T]
11
11
  end
data/sig/node_query.rbs CHANGED
@@ -1,11 +1,11 @@
1
- class NodeQuery
1
+ class NodeQuery[T]
2
2
  VERSION: String
3
3
 
4
4
  def self.configure: (options: { adapter: NodeQuery::Adapter }) -> void
5
5
 
6
- def self.get_adapter: () -> NodeQuery::Adapter
6
+ def self.adapter: () -> NodeQuery::Adapter
7
7
 
8
8
  def initialize: (nql: String) -> NodeQuery
9
9
 
10
- def parse: (node: Node) -> Array[Node]
10
+ def parse: (node: T) -> Array[T]
11
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: node_query
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-27 00:00:00.000000000 Z
11
+ date: 2022-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport