Class: Copland::Configuration::YAML::PackageProcessor
- Inherits:
-
Object
- Object
- Copland::Configuration::YAML::PackageProcessor
- Includes:
- TypeValidator
- Defined in:
- lib/copland/configuration/yaml/package.rb
Overview
This delegate is responsible for processing a package descriptor into a Registry instance.
Constant Summary collapse
- VALID_KEYS =
The list of recognized key values in a package descriptor.
[ "id", "description", "service-points", "configuration-points", "contributions", "require" ]
- REQUIRED_KEYS =
The list of required key values in a package descriptor.
[ "id" ]
Instance Method Summary collapse
-
#initialize(registry, loader) ⇒ PackageProcessor
constructor
Creates a new PackageProcessor that feeds into the given Registry instance.
-
#process(doc, options = {}) ⇒ Object
Process the package descriptor
doc
into the active Registry instance.
Methods included from TypeValidator
#ensure_element_type, #validate_elements
Constructor Details
#initialize(registry, loader) ⇒ PackageProcessor
Creates a new PackageProcessor that feeds into the given Registry instance.
51 52 53 54 |
# File 'lib/copland/configuration/yaml/package.rb', line 51 def initialize( registry, loader ) @registry = registry @loader = loader end |
Instance Method Details
#process(doc, options = {}) ⇒ Object
Process the package descriptor doc
into the active Registry instance. The options
parameter is used when processing service and configuration points within this package descriptor. The new Package instance is added directly to the registry.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/copland/configuration/yaml/package.rb', line 67 def process( doc, ={} ) ensure_element_type "package definition", doc, Hash validate_elements doc package = Package.new( @registry, doc["id"] ) @registry.add_package package doc.each_pair do |key, value| case key when "id" # already discovered and handled above when "description" package.description = value when "service-points" ensure_element_type "service-points", value, Hash processor = ServicePointProcessor.new( package, ) value.each_pair do |name, definition| point = processor.process name, definition package.add_service_point point end when "configuration-points" ensure_element_type "configuration-points", value, Hash processor = ConfigurationPointProcessor.new( package, ) value.each_pair do |name, definition| point = processor.process name, definition package.add_configuration_point point end when "contributions" ensure_element_type "contributions", value, Hash value.each_pair do |name, value| package.add_pending_contribution name, value end when "require" ensure_element_type "require", value, Array value.each do |name| @loader.use_library name end else raise CoplandBug, "[BUG] invalid element discovered too late:" + key.inspect end end end |