Class: Copland::Configuration::YAML::Loader

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

Overview

This is a visitor used during the initialization of a Registry. The Copland::Configuration::Loader class is the driver of the initialization process, and it delegates to visitors. This particular visitor looks for and processes YAML files that describe packages.

Constant Summary collapse

DEFAULT_YAML_CONFIG_FILE =

This is the name of the “configuration” yaml file, which allows parent directories to change certain properties of the processor when processing their children directories.

"copland-config.yml"
DEFAULT_YAML_PACKAGE_FILE =

This is the default name of the package descriptor file.

"package.yml"

Instance Method Summary collapse

Constructor Details

#initialize(registry, loader) ⇒ Loader

Create a new YAML::Loader visitor object that feeds into the given Registry instance.



57
58
59
60
61
# File 'lib/copland/configuration/yaml/loader.rb', line 57

def initialize( registry, loader )
  @parser = Parser.new( registry, loader )
  @registry = registry
  @visited = Hash.new
end

Instance Method Details

#finalize!Object

Finalizes this visitor. This simply calls Registry#fixate!.



87
88
89
# File 'lib/copland/configuration/yaml/loader.rb', line 87

def finalize!
  @registry.fixate! unless @registry.fixated?
end

#process_dir(directory, options) ⇒ Object

This is invoked by the driver when a new directory needs to be visited. The options hash is returned, possibly modified.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/copland/configuration/yaml/loader.rb', line 65

def process_dir( directory, options )
  options_filename = File.join( directory,
    options[ :yaml_options_file ] ||
    DEFAULT_YAML_CONFIG_FILE )

  if File.exist?( options_filename )
    options = parse_options_file( options_filename, options )
  end

  package_filename = File.join( directory,
    options[ :yaml_package_file ] ||
    DEFAULT_YAML_PACKAGE_FILE )

  if !@visited[ package_filename ] && File.exist?( package_filename )
    @visited[ package_filename ] = true
    parse_package_file( package_filename, options )
  end

  return options
end