parser_node_ext 1.3.1 → 1.3.2

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: 50a45e7affbc066c77b4b1ced9b3b9e95f44dda27d545406a81835c3272eada5
4
- data.tar.gz: 20b65501f3e92ea387a1a3f28ec67627cd3c6ea48228a7988c309730a68d380d
3
+ metadata.gz: eaf18e510d010abe73429864f55581cdc6ee4f1dfea42ae2c7e7aebd304f0251
4
+ data.tar.gz: dd1e60ba561f999d822b8c35ac4bb657680fd33c23e606b85f26e859f121b7f9
5
5
  SHA512:
6
- metadata.gz: 69a851d7c5e73797708dd354c5b9f145d6d6c525b234b5be9c2d7c9e79ef690117a1c8c9bdb068a428a0796403d67a91104dd327551c004f42c6168d7e41d92a
7
- data.tar.gz: 660151c08259100c51194e374c8db31ff66fb2acaf76a9f8c41c594029de8ef775f2a4bdc352718860224c31531fca0e63b6cefdb7e85bc1511e1ce26e86a462
6
+ metadata.gz: c4ced2a132a1870df30aaeb0536291a4c239a93bfa7dfc2a8e609f845031b7907358c9158c515b6a27031bfc3c5cb75e657b60662c6f3d09ae432dcd2874c2fb
7
+ data.tar.gz: f38f42bf0d8a7a2b86f435efa04fc9192c36c0a2a1d1ee253a35207fd55ac88aba9388021979b24ac0b9c31111ddc3426a1dec97a69ea81c514254852639fc79
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.3.2 (2024-04-18)
4
+
5
+ * Remove `hash_pair` and `hash_value` methods
6
+
3
7
  ## 1.3.1 (2024-04-18)
4
8
 
5
9
  * Remove `.key?` method
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- parser_node_ext (1.3.1)
4
+ parser_node_ext (1.3.2)
5
5
  parser
6
6
 
7
7
  GEM
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ParserNodeExt
4
- VERSION = "1.3.1"
4
+ VERSION = "1.3.2"
5
5
  end
@@ -319,37 +319,6 @@ module ParserNodeExt
319
319
  end
320
320
  end
321
321
 
322
- # Get :hash pair node according to specified key.
323
- # @example
324
- # node # s(:hash, s(:pair, s(:sym, :foo), s(:sym, :bar)))
325
- # node.hash_pair(:foo) # s(:pair, s(:sym, :foo), s(:sym, :bar))
326
- # @param [Symbol, String] key value.
327
- # @return [Parser::AST::Node] hash pair node.
328
- # @raise [MethodNotSupported] if calls on other node.
329
- def hash_pair(key)
330
- if %i[hash hash_pattern].include?(type)
331
- pairs.find { |pair_node| pair_node.key.to_value == key }
332
- else
333
- raise MethodNotSupported, "hash_pair is not supported for #{self}"
334
- end
335
- end
336
-
337
- # Get :hash value node according to specified key.
338
- # @example
339
- # node # s(:hash, s(:pair, s(:sym, :foo), s(:sym, :bar)))
340
- # node.hash_value(:foo) # s(:sym, :bar)
341
- # @param [Symbol, String] key value.
342
- # @return [Parser::AST::Node] hash value node.
343
- # @raise [MethodNotSupported] if calls on other node.
344
- def hash_value(key)
345
- if %i[hash hash_pattern].include?(type)
346
- value_node = pairs.find { |pair_node| pair_node.key.to_value == key }
347
- value_node&.value
348
- else
349
- raise MethodNotSupported, "hash_value is not supported for #{self}"
350
- end
351
- end
352
-
353
322
  # Get kwsplats of :hash and :hash_pattern node.
354
323
  # @example
355
324
  # node s(:hash, s(:pair, s(:int, 1), s(:int, 2)), s(:kwsplat, s(:send, nil, :bar)), s(:pair, s(:sym, :baz), s(:int, 3)))
@@ -407,22 +376,13 @@ module ParserNodeExt
407
376
  return children.send(method_name, *args, &block)
408
377
  elsif :hash == type && method_name.to_s.end_with?('_pair')
409
378
  key = method_name.to_s[0..-6]
410
- return hash_pair(key.to_sym) if keys.map(&:to_value).include?(key.to_sym)
411
- return hash_pair(key.to_s) if keys.map(&:to_value).include?(key.to_s)
412
-
413
- return nil
379
+ return pairs.find { |pair| pair.key.to_value.to_s == key }
414
380
  elsif :hash == type && method_name.to_s.end_with?('_value')
415
381
  key = method_name.to_s[0..-7]
416
- return hash_value(key.to_sym) if keys.map(&:to_value).include?(key.to_sym)
417
- return hash_value(key.to_s) if keys.map(&:to_value).include?(key.to_s)
418
-
419
- return nil
382
+ return pairs.find { |pair| pair.key.to_value.to_s == key }&.value
420
383
  elsif :hash == type && method_name.to_s.end_with?('_source')
421
384
  key = method_name.to_s[0..-8]
422
- return hash_value(key.to_sym)&.to_source if keys.map(&:to_value).include?(key.to_sym)
423
- return hash_value(key.to_s)&.to_source if keys.map(&:to_value).include?(key.to_s)
424
-
425
- return ''
385
+ return pairs.find { |pair| pair.key.to_value.to_s == key }&.value&.to_source || ''
426
386
  end
427
387
 
428
388
  super
@@ -433,13 +393,13 @@ module ParserNodeExt
433
393
  return true
434
394
  elsif :hash == type && method_name.to_s.end_with?('_pair')
435
395
  key = method_name.to_s[0..-6]
436
- return keys.map(&:to_value).include?(key.to_sym) || keys.map(&:to_value).include?(key.to_s)
396
+ return !!pairs.find { |pair| pair.key.to_value.to_s == key }
437
397
  elsif :hash == type && method_name.to_s.end_with?('_value')
438
398
  key = method_name.to_s[0..-7]
439
- return keys.map(&:to_value).include?(key.to_sym) || keys.map(&:to_value).include?(key.to_s)
399
+ return !!pairs.find { |pair| pair.key.to_value.to_s == key }
440
400
  elsif :hash == type && method_name.to_s.end_with?('_source')
441
401
  key = method_name.to_s[0..-8]
442
- return keys.map(&:to_value).include?(key.to_sym) || keys.map(&:to_value).include?(key.to_s)
402
+ return !!pairs.find { |pair| pair.key.to_value.to_s == key }
443
403
  end
444
404
 
445
405
  super
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parser_node_ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang