Class: YamlVault::KeyParser
- Inherits:
-
Object
- Object
- YamlVault::KeyParser
show all
- Defined in:
- lib/yaml_vault/key_parser.rb
Defined Under Namespace
Classes: InvalidPathFormat
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.parse(str) ⇒ Object
7
8
9
|
# File 'lib/yaml_vault/key_parser.rb', line 7
def self.parse(str)
new.parse(str)
end
|
Instance Method Details
#parse(str) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/yaml_vault/key_parser.rb', line 11
def parse(str)
s = StringScanner.new(str)
path = []
until s.eos?
if token = s.scan(/'(.*?)'/)
path << s[1]
elsif token = s.scan(/"(.*?)"/)
path << s[1]
elsif token = s.scan(%r{/(.*?)/})
path << Regexp.new(s[1])
elsif token = s.scan(/\[(\d+)\]/)
path << s[1].to_i
elsif token = s.scan(/:([^\.]+)/)
path << s[1].to_sym
elsif token = s.scan(/\./)
elsif token = s.scan(/[^\.]*/)
path << token
end
end
raise InvalidPathFormat.new("`$` must be at first") unless path.first == "$"
path
end
|