node_query 1.11.0 → 1.12.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1acc5fa99571d7c0ca697e2719335333716539b1cf9278b98e362b3618a046ed
4
- data.tar.gz: a68d2bd0cba15ed723728e1b47a819a16e1b785346eb301cddc007cc822d5cbc
3
+ metadata.gz: 35243974bb269cb011bc7fb7c4ca8877ef0338cd4cfb8dc80785a06e9b40ee6f
4
+ data.tar.gz: ad100af634d93ddaa21bd37b89c3d0d542645007ee9bcd73c0f8fd28fe7211ae
5
5
  SHA512:
6
- metadata.gz: 80f8e7ccdf4b1a5938dafd6f00ad76a6417258189e0ae006420fc4d633b9656e9c60384fba72c7ec7602068ea6e599b7bc32cddd6c1287eb0ca3d3c3d35e171f
7
- data.tar.gz: d92223f8d1e5792503336f2927ba65f9942250d2314eeb7e950506a0a2a26ef48a802ab2e932f8835a287218ab0b98d45cfc226e389359ab5543198fdb8bafb7
6
+ metadata.gz: 656a13c7124f155c6ed96c5d39a901edd248b4ee1d4b19b2d2205c2f244ba0057dec372087b5a4ba08c5d00e784ae5655a0fee1656befe3061df780e8edc9e7b
7
+ data.tar.gz: e811b204f0cc9848b9c65a85295049e37e7f1bf2cb1897f79236093af95a941133962ae425d125c103e123da9019960d00ddf4c41850e868cf5fabd7c245f64a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.12.1 (2023-04-06)
4
+
5
+ * Fix when `actual` is nil
6
+
7
+ ## 1.12.0 (2023-01-16)
8
+
9
+ * Drop `activesupport`
10
+ * Remove `NodeQuery::AnyValue`
11
+
3
12
  ## 1.11.0 (2022-12-09)
4
13
 
5
14
  * Support negative index to fetch array element
data/Gemfile.lock CHANGED
@@ -1,21 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- node_query (1.11.0)
5
- activesupport (< 7.0.0)
4
+ node_query (1.12.1)
6
5
 
7
6
  GEM
8
7
  remote: https://rubygems.org/
9
8
  specs:
10
- activesupport (6.1.7)
11
- concurrent-ruby (~> 1.0, >= 1.0.2)
12
- i18n (>= 1.6, < 2)
13
- minitest (>= 5.1)
14
- tzinfo (~> 2.0)
15
- zeitwerk (~> 2.3)
16
9
  ast (2.4.2)
17
10
  coderay (1.1.3)
18
- concurrent-ruby (1.1.10)
19
11
  diff-lcs (1.5.0)
20
12
  ffi (1.15.5)
21
13
  formatador (1.1.0)
@@ -36,27 +28,24 @@ GEM
36
28
  guard (~> 2.1)
37
29
  guard-compat (~> 1.1)
38
30
  rspec (>= 2.99.0, < 4.0)
39
- i18n (1.12.0)
40
- concurrent-ruby (~> 1.0)
41
31
  listen (3.7.1)
42
32
  rb-fsevent (~> 0.10, >= 0.10.3)
43
33
  rb-inotify (~> 0.9, >= 0.9.10)
44
34
  lumberjack (1.2.8)
45
35
  method_source (1.0.0)
46
- minitest (5.16.3)
47
36
  nenv (0.3.0)
48
37
  notiffany (0.1.3)
49
38
  nenv (~> 0.1)
50
39
  shellany (~> 0.0)
51
40
  oedipus_lex (2.6.0)
52
- parser (3.1.2.0)
41
+ parser (3.2.1.1)
53
42
  ast (~> 2.4.1)
54
- parser_node_ext (0.4.0)
43
+ parser_node_ext (1.0.0)
55
44
  parser
56
45
  pry (0.14.1)
57
46
  coderay (~> 1.1)
58
47
  method_source (~> 1.0)
59
- racc (1.6.0)
48
+ racc (1.6.2)
60
49
  rake (13.0.6)
61
50
  rb-fsevent (0.11.1)
62
51
  rb-inotify (0.10.1)
@@ -76,9 +65,6 @@ GEM
76
65
  rspec-support (3.11.0)
77
66
  shellany (0.0.1)
78
67
  thor (1.2.1)
79
- tzinfo (2.0.5)
80
- concurrent-ruby (~> 1.0)
81
- zeitwerk (2.6.6)
82
68
 
83
69
  PLATFORMS
84
70
  x86_64-darwin-21
data/README.md CHANGED
@@ -115,7 +115,7 @@ It matches class node whose parent class name is Base
115
115
  ### nql matches evaluated value
116
116
 
117
117
  ```
118
- .ivasgn[left_value="@{{right_value}}"]
118
+ .ivasgn[variable="@{{value}}"]
119
119
  ```
120
120
 
121
121
  It matches ivasgn node whose left value equals '@' plus the evaluated value of right value.
@@ -271,7 +271,7 @@ It matches send node whose parent is def node.
271
271
  #### Adjacent sibling combinator
272
272
 
273
273
  ```
274
- .send[left_value=@id] + .send
274
+ .send[variable=@id] + .send
275
275
  ```
276
276
 
277
277
  It matches send node only if it is immediately follows the send node whose left value is @id.
@@ -279,7 +279,7 @@ It matches send node only if it is immediately follows the send node whose left
279
279
  #### General sibling combinator
280
280
 
281
281
  ```
282
- .send[left_value=@id] ~ .send
282
+ .send[variable=@id] ~ .send
283
283
  ```
284
284
 
285
285
  It matches send node only if it is follows the send node whose left value is @id.
@@ -323,7 +323,7 @@ It matches the last def node.
323
323
  ### nql matches multiple expressions
324
324
 
325
325
  ```
326
- .ivasgn[left_value=@id], .ivasgn[left_value=@name]
326
+ .ivasgn[variable=@id], .ivasgn[variable=@name]
327
327
  ```
328
328
 
329
329
  It matches ivasgn node whose left value is either @id or @name.
@@ -363,7 +363,7 @@ It matches class node whose parent class name is Base
363
363
  ### rules matches evaluated value
364
364
 
365
365
  ```
366
- { node_type: 'ivasgn', left_value: '@{{right_value}}' }
366
+ { node_type: 'ivasgn', variable: '@{{value}}' }
367
367
  ```
368
368
 
369
369
  It matches ivasgn node whose left value equals '@' plus the evaluated value of right value.
@@ -35,4 +35,4 @@ class NodeQuery::Adapter
35
35
  def get_siblings(node)
36
36
  raise NotImplementedError, 'get_siblings is not implemented'
37
37
  end
38
- end
38
+ end
@@ -18,7 +18,10 @@ module NodeQuery::Compiler
18
18
  def match?(node, base_node, _operator = '==')
19
19
  return false unless node
20
20
 
21
- @node_type.to_sym == NodeQuery.adapter.get_node_type(node) && (!@attribute_list || @attribute_list.match?(node, base_node))
21
+ @node_type.to_sym == NodeQuery.adapter.get_node_type(node) && (!@attribute_list || @attribute_list.match?(
22
+ node,
23
+ base_node
24
+ ))
22
25
  end
23
26
 
24
27
  def to_s
@@ -25,7 +25,9 @@ module NodeQuery::Compiler
25
25
  when '!='
26
26
  if expected.is_a?(::Array)
27
27
  !actual.is_a?(::Array) || actual.size != expected.size ||
28
- actual.zip(expected).any? { |actual_child, expected_child| expected_child.match?(actual_child, base_node, '!=') }
28
+ actual.zip(expected).any? { |actual_child, expected_child|
29
+ expected_child.match?(actual_child, base_node, '!=')
30
+ }
29
31
  else
30
32
  !is_equal?(actual, expected)
31
33
  end
@@ -66,7 +68,9 @@ module NodeQuery::Compiler
66
68
  else
67
69
  if expected.is_a?(::Array)
68
70
  actual.is_a?(::Array) && actual.size == expected.size &&
69
- actual.zip(expected).all? { |actual_child, expected_child| expected_child.match?(actual_child, base_node, '==') }
71
+ actual.zip(expected).all? { |actual_child, expected_child|
72
+ expected_child.match?(actual_child, base_node, '==')
73
+ }
70
74
  else
71
75
  is_equal?(actual, expected)
72
76
  end
@@ -110,7 +114,7 @@ module NodeQuery::Compiler
110
114
  # Get the expected value
111
115
  # @param base_node [Node] the base node for evaluated value
112
116
  # @return expected value, could be integer, float, string, boolean, nil, range, and etc.
113
- def expected_value(base_node)
117
+ def expected_value(_base_node)
114
118
  @value
115
119
  end
116
120
 
@@ -12,7 +12,15 @@ module NodeQuery::Compiler
12
12
  # @param attribute_list [NodeQuery::Compiler::AttributeList] the attribute list
13
13
  # @param pseudo_class [String] the pseudo class, can be <code>has</code> or <code>not_has</code>
14
14
  # @param pseudo_selector [NodeQuery::Compiler::Expression] the pseudo selector
15
- def initialize(goto_scope: nil, relationship: nil, rest: nil, basic_selector: nil, position: nil, pseudo_class: nil, pseudo_selector: nil)
15
+ def initialize(
16
+ goto_scope: nil,
17
+ relationship: nil,
18
+ rest: nil,
19
+ basic_selector: nil,
20
+ position: nil,
21
+ pseudo_class: nil,
22
+ pseudo_selector: nil
23
+ )
16
24
  @goto_scope = goto_scope
17
25
  @relationship = relationship
18
26
  @rest = rest
@@ -36,7 +44,10 @@ module NodeQuery::Compiler
36
44
  return false
37
45
  end
38
46
  end
39
- NodeQuery.adapter.is_node?(node) && (!@basic_selector || (operator == "!=" ? !@basic_selector.match?(node, base_node) : @basic_selector.match?(node, base_node))) && match_pseudo_class?(node)
47
+ NodeQuery.adapter.is_node?(node) && (!@basic_selector || (operator == "!=" ? !@basic_selector.match?(
48
+ node,
49
+ base_node
50
+ ) : @basic_selector.match?(node, base_node))) && match_pseudo_class?(node)
40
51
  end
41
52
 
42
53
  # Query nodes by the selector.
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class NodeQuery::Helper
4
- class <<self
4
+ class << self
5
5
  # Get target node by the keys.
6
6
  # @param node [Node] ast node
7
7
  # @param keys [String|Array] keys of child node.
@@ -43,7 +43,7 @@ class NodeQuery::Helper
43
43
  # Evaluate node value.
44
44
  # @example
45
45
  # source code of the node is @id = id
46
- # evaluated_node_value(node, "@{{right_value}}") # => @id
46
+ # evaluated_node_value(node, "@{{value}}") # => @id
47
47
  # @param node [Node] ast node
48
48
  # @param str [String] string to be evaluated
49
49
  # @return [String] evaluated string
@@ -63,4 +63,4 @@ class NodeQuery::Helper
63
63
  node.to_s
64
64
  end
65
65
  end
66
- end
66
+ end
@@ -22,7 +22,7 @@ class NodeQuery::NodeRules
22
22
  return match_node?(node) ? [node] : []
23
23
  end
24
24
 
25
- matching_nodes = []
25
+ matching_nodes = []
26
26
  if options[:including_self] && match_node?(node)
27
27
  matching_nodes.push(node)
28
28
  return matching_nodes if options[:stop_at_first_match]
@@ -51,9 +51,10 @@ class NodeQuery::NodeRules
51
51
  def match_node?(node)
52
52
  flat_hash(@rules).keys.all? do |multi_keys|
53
53
  last_key = multi_keys.last
54
- actual = KEYWORDS.include?(last_key) ?
55
- NodeQuery::Helper.get_target_node(node, multi_keys[0...-1].join('.')) :
56
- NodeQuery::Helper.get_target_node(node, multi_keys.join('.'))
54
+ actual =
55
+ KEYWORDS.include?(last_key) ?
56
+ NodeQuery::Helper.get_target_node(node, multi_keys[0...-1].join('.')) :
57
+ NodeQuery::Helper.get_target_node(node, multi_keys.join('.'))
57
58
  expected = expected_value(@rules, multi_keys)
58
59
  expected = NodeQuery::Helper.evaluate_node_value(node, expected) if expected.is_a?(String)
59
60
  case last_key
@@ -131,13 +132,11 @@ class NodeQuery::NodeRules
131
132
  actual == expected
132
133
  end
133
134
  when TrueClass
134
- :true == actual.type
135
+ :true == actual&.type
135
136
  when FalseClass
136
- :false == actual.type
137
+ :false == actual&.type
137
138
  when Parser::AST::Node
138
139
  actual == expected
139
- when NodeQuery::AnyValue
140
- !actual.nil?
141
140
  else
142
141
  raise NodeQuery::MethodNotSupported, "#{expected} is not supported"
143
142
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class NodeQuery
4
- VERSION = "1.11.0"
4
+ VERSION = "1.12.1"
5
5
  end
data/lib/node_query.rb CHANGED
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_support/core_ext/array'
4
-
5
3
  require_relative "node_query/version"
6
4
  require_relative "./node_query_lexer.rex"
7
5
  require_relative "./node_query_parser.racc"
@@ -14,7 +12,6 @@ class NodeQuery
14
12
  autoload :Compiler, "node_query/compiler"
15
13
  autoload :Helper, "node_query/helper"
16
14
  autoload :NodeRules, "node_query/node_rules"
17
- autoload :AnyValue, 'node_query/any_value'
18
15
 
19
16
  # Configure NodeQuery
20
17
  # @param [Hash] options options to configure
data/node_query.gemspec CHANGED
@@ -28,9 +28,6 @@ Gem::Specification.new do |spec|
28
28
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
29
  spec.require_paths = ["lib"]
30
30
 
31
- # Uncomment to register a new dependency of your gem
32
- spec.add_dependency "activesupport", "< 7.0.0"
33
-
34
31
  # For more information and examples about making a new gem, check out our
35
32
  # guide at: https://bundler.io/guides/creating_gem.html
36
33
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: node_query
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.0
4
+ version: 1.12.1
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-12-09 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: activesupport
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "<"
18
- - !ruby/object:Gem::Version
19
- version: 7.0.0
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "<"
25
- - !ruby/object:Gem::Version
26
- version: 7.0.0
11
+ date: 2023-04-05 00:00:00.000000000 Z
12
+ dependencies: []
27
13
  description: ast node query language
28
14
  email:
29
15
  - flyerhzm@gmail.com
@@ -40,7 +26,6 @@ files:
40
26
  - Rakefile
41
27
  - lib/node_query.rb
42
28
  - lib/node_query/adapter.rb
43
- - lib/node_query/any_value.rb
44
29
  - lib/node_query/compiler.rb
45
30
  - lib/node_query/compiler/array_value.rb
46
31
  - lib/node_query/compiler/attribute.rb
@@ -92,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
77
  - !ruby/object:Gem::Version
93
78
  version: '0'
94
79
  requirements: []
95
- rubygems_version: 3.3.26
80
+ rubygems_version: 3.4.10
96
81
  signing_key:
97
82
  specification_version: 4
98
83
  summary: ast node query language
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # A new type to match any value.
4
- class NodeQuery::AnyValue
5
- end