Class: Copland::Configuration::YAML::ServicePointProcessor

Inherits:
Object
  • Object
show all
Includes:
TypeValidator
Defined in:
lib/copland/configuration/yaml/service-point.rb

Overview

This is the delgate that is responsible for processing the input describing a service point.

Constant Summary collapse

VALID_KEYS =

The list of valid keys that may exist on the input.

[ "description", "model", "implementor",
"interceptors", "listen-to", "schema",
"visibility" ]
REQUIRED_KEYS =

The list of required keys that must exist on the input.

[ "implementor" ]

Instance Method Summary collapse

Methods included from TypeValidator

#ensure_element_type, #validate_elements

Constructor Details

#initialize(package, options = {}) ⇒ ServicePointProcessor

Create a new ServicePointProcessor that feeds into the given package instance. The options parameter is given to every new service point as it is created.



54
55
56
57
58
59
60
61
# File 'lib/copland/configuration/yaml/service-point.rb', line 54

def initialize( package, options={} )
  @package = package
  @options = options
  @implementor = ImplementorProcessor.new
  @interceptor = InterceptorProcessor.new
  @listener = ListenerProcessor.new
  @schema = SchemaParser.new
end

Instance Method Details

#process(name, doc) ⇒ Object

Create a new service point with the given name and populate it with data as described by the doc parameter. The new service point is returned.



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/service-point.rb', line 74

def process( name, doc )
  ensure_element_type "service-point", doc, Hash
  validate_elements doc

  point = ServicePoint.new( @package, name, @options )
  doc.each_pair do |key, value|
    case key
      when "description"
        point.description = value

      when "model"
        point.use_service_model value

      when "implementor"
        @implementor.process( point, value )

      when "interceptors"
        ensure_element_type "interceptors", value, Array
        value.each do |definition|
          @interceptor.process( point, definition )
        end

      when "listen-to"
        ensure_element_type "listen-to", value, Array
        value.each do |definition|
          @listener.process( point, definition )
        end

      when "schema"
        point.schema = @schema.process( point, value )

      when "visibility"
        point.visibility = case value.downcase
          when "public" then :public
          when "private" then :private
          else raise ParserError,
            "invalid visibility value #{value.inspect}"
          end

      else
        raise CoplandBug, "[BUG] invalid key discovered too late: #{key.inspect}"
    end
  end

  return point
end