Class: Copland::Configuration::YAML::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/copland/configuration/yaml/parser.rb

Overview

Manages the parsing and processing of YAML input into package instances that can be added to a Registry.

Instance Method Summary collapse

Constructor Details

#initialize(registry, loader) ⇒ Parser

Create a new parser that will feed into the given Registry instance.



47
48
49
50
# File 'lib/copland/configuration/yaml/parser.rb', line 47

def initialize( registry, loader )
  @registry = registry
  @package = PackageProcessor.new( @registry, loader )
end

Instance Method Details

#parse(io, options = {}) ⇒ Object

Parse the given io parameter (which must be either an IO object or a String). The options are passed through to the PackageProcessor instance.



61
62
63
64
65
# File 'lib/copland/configuration/yaml/parser.rb', line 61

def parse( io, options={} )
  ::YAML.load_documents( io ) do |doc|
    @package.process doc, options
  end
end

#parse_file(filename, options = {}) ⇒ Object

Parse the file with the given name. The options Hash is optional, and specifies values that determine how the parse occurs.



54
55
56
# File 'lib/copland/configuration/yaml/parser.rb', line 54

def parse_file( filename, options={} )
  parse( File.read( filename ) )
end