parser_node_ext 1.3.0 → 1.3.2

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: 3f58dd28166500b9ae0882d5a629d272f4ad7713538e2f7aeb2a0218c77a359a
4
- data.tar.gz: 3947994cf6a5669d2d37971af8dae83836a429c9715aa2c2e29a7efd3c74863a
3
+ metadata.gz: eaf18e510d010abe73429864f55581cdc6ee4f1dfea42ae2c7e7aebd304f0251
4
+ data.tar.gz: dd1e60ba561f999d822b8c35ac4bb657680fd33c23e606b85f26e859f121b7f9
5
5
  SHA512:
6
- metadata.gz: 3e2462943a0c6db7a0e2d95a9ce9e967deb19c5d2a7ce71d44b68c7db5cb74bbf398d2ae487ea0db8145371d4c7ec17910c5889d675d9201b19e81ae7ab041d4
7
- data.tar.gz: f8b0f07ff32914d11bb1a3cc70e1a6b2a19501bdb08d795334c738780fa4cfa016a18e86e3014f80b86953eba7e06e44dcfca4d67680e7bb0e35e52f9402f9e0
6
+ metadata.gz: c4ced2a132a1870df30aaeb0536291a4c239a93bfa7dfc2a8e609f845031b7907358c9158c515b6a27031bfc3c5cb75e657b60662c6f3d09ae432dcd2874c2fb
7
+ data.tar.gz: f38f42bf0d8a7a2b86f435efa04fc9192c36c0a2a1d1ee253a35207fd55ac88aba9388021979b24ac0b9c31111ddc3426a1dec97a69ea81c514254852639fc79
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.3.2 (2024-04-18)
4
+
5
+ * Remove `hash_pair` and `hash_value` methods
6
+
7
+ ## 1.3.1 (2024-04-18)
8
+
9
+ * Remove `.key?` method
10
+
3
11
  ## 1.3.0 (2024-04-07)
4
12
 
5
13
  * Add github actions
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- parser_node_ext (1.3.0)
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.0"
4
+ VERSION = "1.3.2"
5
5
  end
@@ -319,52 +319,6 @@ module ParserNodeExt
319
319
  end
320
320
  end
321
321
 
322
- # Check if :hash node contains specified key.
323
- # @example
324
- # node # s(:hash, s(:pair, s(:sym, :foo), s(:sym, :bar)))
325
- # node.key?(:foo) # true
326
- # @param [Symbol, String] key value.
327
- # @return [Boolean] true if specified key exists.
328
- # @raise [MethodNotSupported] if calls on other node.
329
- def key?(key)
330
- if %i[hash hash_pattern].include?(type)
331
- pairs.any? { |pair_node| pair_node.key.to_value == key }
332
- else
333
- raise MethodNotSupported, "key? is not supported for #{self}"
334
- end
335
- end
336
-
337
- # Get :hash pair node according to specified key.
338
- # @example
339
- # node # s(:hash, s(:pair, s(:sym, :foo), s(:sym, :bar)))
340
- # node.hash_pair(:foo) # s(:pair, s(:sym, :foo), s(:sym, :bar))
341
- # @param [Symbol, String] key value.
342
- # @return [Parser::AST::Node] hash pair node.
343
- # @raise [MethodNotSupported] if calls on other node.
344
- def hash_pair(key)
345
- if %i[hash hash_pattern].include?(type)
346
- pairs.find { |pair_node| pair_node.key.to_value == key }
347
- else
348
- raise MethodNotSupported, "hash_pair is not supported for #{self}"
349
- end
350
- end
351
-
352
- # Get :hash value node according to specified key.
353
- # @example
354
- # node # s(:hash, s(:pair, s(:sym, :foo), s(:sym, :bar)))
355
- # node.hash_value(:foo) # s(:sym, :bar)
356
- # @param [Symbol, String] key value.
357
- # @return [Parser::AST::Node] hash value node.
358
- # @raise [MethodNotSupported] if calls on other node.
359
- def hash_value(key)
360
- if %i[hash hash_pattern].include?(type)
361
- value_node = pairs.find { |pair_node| pair_node.key.to_value == key }
362
- value_node&.value
363
- else
364
- raise MethodNotSupported, "hash_value is not supported for #{self}"
365
- end
366
- end
367
-
368
322
  # Get kwsplats of :hash and :hash_pattern node.
369
323
  # @example
370
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)))
@@ -422,22 +376,13 @@ module ParserNodeExt
422
376
  return children.send(method_name, *args, &block)
423
377
  elsif :hash == type && method_name.to_s.end_with?('_pair')
424
378
  key = method_name.to_s[0..-6]
425
- return hash_pair(key.to_sym) if key?(key.to_sym)
426
- return hash_pair(key.to_s) if key?(key.to_s)
427
-
428
- return nil
379
+ return pairs.find { |pair| pair.key.to_value.to_s == key }
429
380
  elsif :hash == type && method_name.to_s.end_with?('_value')
430
381
  key = method_name.to_s[0..-7]
431
- return hash_value(key.to_sym) if key?(key.to_sym)
432
- return hash_value(key.to_s) if key?(key.to_s)
433
-
434
- return nil
382
+ return pairs.find { |pair| pair.key.to_value.to_s == key }&.value
435
383
  elsif :hash == type && method_name.to_s.end_with?('_source')
436
384
  key = method_name.to_s[0..-8]
437
- return hash_value(key.to_sym)&.to_source if key?(key.to_sym)
438
- return hash_value(key.to_s)&.to_source if key?(key.to_s)
439
-
440
- return ''
385
+ return pairs.find { |pair| pair.key.to_value.to_s == key }&.value&.to_source || ''
441
386
  end
442
387
 
443
388
  super
@@ -448,13 +393,13 @@ module ParserNodeExt
448
393
  return true
449
394
  elsif :hash == type && method_name.to_s.end_with?('_pair')
450
395
  key = method_name.to_s[0..-6]
451
- return key?(key.to_sym) || key?(key.to_s)
396
+ return !!pairs.find { |pair| pair.key.to_value.to_s == key }
452
397
  elsif :hash == type && method_name.to_s.end_with?('_value')
453
398
  key = method_name.to_s[0..-7]
454
- return key?(key.to_sym) || key?(key.to_s)
399
+ return !!pairs.find { |pair| pair.key.to_value.to_s == key }
455
400
  elsif :hash == type && method_name.to_s.end_with?('_source')
456
401
  key = method_name.to_s[0..-8]
457
- return key?(key.to_sym) || key?(key.to_s)
402
+ return !!pairs.find { |pair| pair.key.to_value.to_s == key }
458
403
  end
459
404
 
460
405
  super
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parser_node_ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-04-07 00:00:00.000000000 Z
11
+ date: 2024-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser