Module: TraceableYAML
- Defined in:
- lib/traceable.rb
Class Method Summary collapse
-
.load_file(path, tag) ⇒ Object
Load a YAML document from the file
path, tagging each value with the sourcetag, and return a Ruby object tree representing the result. -
.parse(doc, tag) ⇒ Object
Parse a YAML document from the string
doc, tagging each value with the sourcetag, and return a Ruby object tree representing the result.
Class Method Details
.load_file(path, tag) ⇒ Object
Load a YAML document from the file path, tagging each value with the source tag, and return a Ruby object tree representing the result.
211 212 213 214 215 |
# File 'lib/traceable.rb', line 211 def self.load_file(path, tag) File.open(path) do |f| parse(f.read, tag) end end |
.parse(doc, tag) ⇒ Object
Parse a YAML document from the string doc, tagging each value with the source tag, and return a Ruby object tree representing the result.
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/traceable.rb', line 192 def self.parse(doc, tag) handler = PositionHandler.new(tag) parser = Psych::Parser.new(handler) handler.parser = parser parser.parse doc if PositionVisitor.respond_to?(:create) # Ruby 2.1 and above visitor = PositionVisitor.create else # Ruby 2.0 visitor = PositionVisitor.new end tree = visitor.accept(handler.root) tree[0] end |