Module: Copland::ConfigurationPoint::ConfigurationPointFunctionality

Included in:
ListConfigurationPoint, MapConfigurationPoint
Defined in:
lib/copland/configuration-point/common.rb

Overview

This module implements the functionality that is common to all configuration points. By making this a module (as opposed to making it a class and having all configuration points extend it), you can now have configuration points that extend existing container classes, and which simply include this module.

Defined Under Namespace

Modules: Fixated

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#descriptionObject

The (optional) description of this configuration point.



78
79
80
# File 'lib/copland/configuration-point/common.rb', line 78

def description
  @description
end

#nameObject (readonly)

The name of the configuration point.



72
73
74
# File 'lib/copland/configuration-point/common.rb', line 72

def name
  @name
end

#ownerObject (readonly)

The package instance that owns this configuration point.



75
76
77
# File 'lib/copland/configuration-point/common.rb', line 75

def owner
  @owner
end

#schemaObject

The (optional) schema that describes the value format of any data contributed to this configuration point.



82
83
84
# File 'lib/copland/configuration-point/common.rb', line 82

def schema
  @schema
end

Instance Method Details

#assert_correct_type(values) ⇒ Object

Assert that the values parameter is of the correct type for this configuration point.



133
134
135
136
137
# File 'lib/copland/configuration-point/common.rb', line 133

def assert_correct_type( values )
  unless values.is_a?( self.class.superclass )
    raise ContributionTypeMismatch, values.class.inspect
  end
end

#contribute(values) ⇒ Object

Contribute the given values to the configuration point. The values parameter must be of the correct type for this configuration point.



112
113
114
115
116
117
# File 'lib/copland/configuration-point/common.rb', line 112

def contribute( values )
  assert_correct_type( values )
  validate_values( values )
  values = process_values( values )
  assimilate_values( values )
end

#contributor_of(values) ⇒ Object

Obtain a reference to the entity that made the given contribution. The entity is returned as an object that responds to :owner, which will return the contributing package when invoked.



122
123
124
125
126
127
128
129
# File 'lib/copland/configuration-point/common.rb', line 122

def contributor_of( values )
  contributor = values.instance_variable_get( :@contributor )
  if contributor
    return OpenStruct.new( :owner => contributor )
  else
    return self
  end
end

#fixate!Object

Fixate the configuration point. This finalizes certain properties of the point, such as the schema. Once fixated, fixating a configuration point again will do nothing.



101
102
103
104
105
106
107
108
# File 'lib/copland/configuration-point/common.rb', line 101

def fixate!
  extend Fixated
  if @schema.is_a?( String )
    @schema = @owner.find_schema( @schema )
  elsif !@schema.nil?
    @schema.fixate!
  end
end

#fixated?Boolean

Returns false. Once a configuration point is fixated, it will include the Copland::ConfigurationPoint::ConfigurationPointFunctionality::Fixated module, which redefines this method, as well as #fixate!.

Returns:

  • (Boolean)


211
212
213
# File 'lib/copland/configuration-point/common.rb', line 211

def fixated?
  false
end

#full_nameObject

Return the fully qualified name of this configuration point, which is the name of the package and the name of the point, separated by a dot.



94
95
96
# File 'lib/copland/configuration-point/common.rb', line 94

def full_name
  owner.name + "." + name
end

#initialize(owner, name, options = {}) ⇒ Object

Initializes the new configuration point with the given owner and name. The options parameter is optional, and currently does nothing.



86
87
88
89
90
# File 'lib/copland/configuration-point/common.rb', line 86

def initialize( owner, name, options={} )
  super()
  @owner = owner
  @name = name
end

#process_values(values) ⇒ Object

Process and return the values parameter according to the schema for this configuration point; or if no schema exists, run the values through the Copland::translate_values method.



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/copland/configuration-point/common.rb', line 158

def process_values( values )
  Thread.current[:disable_symbol_substitution] = true
  s = schema
  contributor = contributor_of( values )
  if s.respond_to?( :process )
    if values.is_a?( Array )
      values = values.map! { |value|
        s.process( self, contributor, value )
      }
    else
      values = s.process( self, contributor, values )
    end
  else
    values = Copland::translate_value( contributor.owner.registry,
      contributor.owner, self, values )
  end

  return values
ensure
  Thread.current[:disable_symbol_substitution] = false
end

#substitute_symbols!Object

Processes all substitution symbols in the values of this configuration point, in place. This has a guard to ensure that it is only executed once.



183
184
185
186
187
188
189
190
# File 'lib/copland/configuration-point/common.rb', line 183

def substitute_symbols!
  Thread.critical = true
  return if @substitution_processed
  @substitution_processed = true
  substitute_symbols( self )
ensure
  Thread.critical = false
end

#validate_values(values) ⇒ Object

Assert that the values parameter is valid according to the schema for this configuration point.



141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/copland/configuration-point/common.rb', line 141

def validate_values( values )
  s = schema
  if s.respond_to?( :validate )
    contributor = contributor_of( values )
    if values.is_a?( Array )
      values.each do |value|
        s.validate self, contributor, value
      end
    else
      s.validate self, contributor, values
    end
  end
end