static_literal_parser 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/static_literal_parser.rb +19 -1
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b459bba28eff1d442f3b263827bd3fac5899c57e8f7eb6505b8f88f377ed0f4
4
- data.tar.gz: '0937a15bf39622e403c00a37f0b4457321b039ca5a5afd71ee1208708273b4a7'
3
+ metadata.gz: 9fd90d1bbf587025109b4bbd0a1458cc031f8b6cef5137fc90b7f0052e1b0f7e
4
+ data.tar.gz: 161e4c1bc731ff18b1f748abc717e59c47b6906c5456637336754a304671f298
5
5
  SHA512:
6
- metadata.gz: 2eb6b4fbbf20b88b961caa97e6a8f197531a78b563a88124f18149d02ead1e21bd8817df05a99ae2cc906a0470b09199693859468806c3dbccca0491cac1ade2
7
- data.tar.gz: 8bb488da5a444b33cbb4ef11bb9946375c3ced23f7feee56ace30a2faca1475dab605337027017718eb5e4fc349eac9c62977c5f213f824490102d9acaadcbba
6
+ metadata.gz: 59fecb14ab67a2550b537fd4e8bf6063027c4b3ac5e30dbdfa10f2c1ac4f8b2db0efdd4df6e45a30ffd6e5ba301e7bb23ba2daf7968e9e4e1351bb7c3699f54a
7
+ data.tar.gz: a74fbfb68fa4201ccd5adc6ed5fbb7c06884b9ec0e1088a4437c257ad5e9b17dec09a6a5bbadd753aa46934cdd40a5207acac920e089af91b273fe22a66e6fbb
@@ -2,7 +2,14 @@
2
2
 
3
3
  module StaticLiteralParser
4
4
  def self.parse(str, constants)
5
- parse_(RubyVM::AbstractSyntaxTree.parse(str), constants)
5
+ case constants
6
+ when Array
7
+ parse(str, constant_strs_array_to_hash(constants))
8
+ when Hash
9
+ parse_(RubyVM::AbstractSyntaxTree.parse(str), constants)
10
+ else
11
+ raise ArgumentError, "Unsupported constants type: #{constants}"
12
+ end
6
13
  end
7
14
 
8
15
  private_class_method def self.parse_(node, constants)
@@ -32,4 +39,15 @@ module StaticLiteralParser
32
39
  raise "Unexpected node #{node.type}"
33
40
  end
34
41
  end
42
+
43
+ private_class_method def self.constant_strs_array_to_hash(constant_strs_array)
44
+ constant_strs_array.flat_map {|constant|
45
+ constant.split('::').inject([]) {|memo, part|
46
+ [*memo, [memo.last, part].compact.join('::')]
47
+ }
48
+ }.to_h {|name|
49
+ c = Object.const_get(name)
50
+ [name.to_sym, c]
51
+ }
52
+ end
35
53
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: static_literal_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tatsuhiro Ujihisa