Class: Copland::Package
- Inherits:
-
Object
- Object
- Copland::Package
- Defined in:
- lib/copland/package.rb
Overview
This represents a single package in a Repository.
Defined Under Namespace
Modules: Fixated
Instance Attribute Summary collapse
-
#description ⇒ Object
The description of the package.
-
#name ⇒ Object
readonly
The name of this package.
-
#registry ⇒ Object
readonly
The Registry instance that contains this package.
Instance Method Summary collapse
-
#add_configuration_point(configuration_point) ⇒ Object
Add the given configuration point to the package.
-
#add_pending_contribution(name, value) ⇒ Object
Adds a “pending” contribution to the package.
-
#add_schema(schema) ⇒ Object
Add the given schema to the package.
-
#add_service_point(service_point) ⇒ Object
Add the given service point to the package.
-
#configuration_point(name) ⇒ Object
Returns the configuration point with the given name, or
nil
if no such configuration point exists. -
#configuration_point_count ⇒ Object
Returns the number of configuration points in the package.
-
#configuration_points ⇒ Object
Returns the names of all configuration points in the package.
-
#each_configuration_point(&block) ⇒ Object
Iterates over each configuration point in the package.
-
#each_schema(&block) ⇒ Object
Iterates over each schema in the package.
-
#each_service_point(&block) ⇒ Object
Iterates over each service point in the package.
-
#find_schema(name) ⇒ Object
This is a convenience method for returning a schema with the given name, giving preference when a package is not specified to the schemas within the current package.
-
#find_service(name, &block) ⇒ Object
This is a convenience method for returning a service with the given name, giving preference when a package is not specified to the service points within the current package.
-
#fixate! ⇒ Object
Fixates the package.
-
#fixated? ⇒ Boolean
Returns
false
, although when the package is fixated this will be overridden with a method that will returntrue
. -
#initialize(registry, name) ⇒ Package
constructor
Create a new package associated with the given registry.
-
#schema(name) ⇒ Object
Returns the schema with the given name, or
nil
if no such schema exists. -
#schema_count ⇒ Object
Returns the number of schemas in the package.
-
#service(name, &init) ⇒ Object
This instantiates the service point with the given name and returns the resulting service.
-
#service_exist?(name) ⇒ Boolean
Returns
true
if the named service exists in this package, andfalse
otherwise. -
#service_point(name) ⇒ Object
Returns the service point with the given name.
-
#service_point_count ⇒ Object
Returns the number of service points in the package.
-
#service_points ⇒ Object
This returns the names of all service points in the package.
Constructor Details
#initialize(registry, name) ⇒ Package
Create a new package associated with the given registry. The package will have the given name. Note: this will not add the package to the registry!
54 55 56 57 58 59 60 |
# File 'lib/copland/package.rb', line 54 def initialize( registry, name ) @registry = registry @name = name @service_points = Hash.new @configuration_points = Hash.new @schemas = Hash.new end |
Instance Attribute Details
#description ⇒ Object
The description of the package.
49 50 51 |
# File 'lib/copland/package.rb', line 49 def description @description end |
#name ⇒ Object (readonly)
The name of this package.
46 47 48 |
# File 'lib/copland/package.rb', line 46 def name @name end |
#registry ⇒ Object (readonly)
The Registry instance that contains this package.
43 44 45 |
# File 'lib/copland/package.rb', line 43 def registry @registry end |
Instance Method Details
#add_configuration_point(configuration_point) ⇒ Object
Add the given configuration point to the package.
68 69 70 |
# File 'lib/copland/package.rb', line 68 def add_configuration_point( configuration_point ) @configuration_points[ configuration_point.name ] = configuration_point end |
#add_pending_contribution(name, value) ⇒ Object
Adds a “pending” contribution to the package. When the package is fixated (see #fixate!), the given value will be contributed to the configuration point with the given name. Once the package is fixated, this method will be illegal to invoke.
152 153 154 155 |
# File 'lib/copland/package.rb', line 152 def add_pending_contribution( name, value ) ( @pending_contributions ||= [] ).push :name => name, :value => value end |
#add_schema(schema) ⇒ Object
Add the given schema to the package. Note that this requires that the schema have a name. This will also set the schema’s owner
attribute to the package.
75 76 77 78 |
# File 'lib/copland/package.rb', line 75 def add_schema( schema ) schema.owner = self @schemas[ schema.name ] = schema end |
#add_service_point(service_point) ⇒ Object
Add the given service point to the package.
63 64 65 |
# File 'lib/copland/package.rb', line 63 def add_service_point( service_point ) @service_points[ service_point.name ] = service_point end |
#configuration_point(name) ⇒ Object
Returns the configuration point with the given name, or nil
if no such configuration point exists.
133 134 135 |
# File 'lib/copland/package.rb', line 133 def configuration_point( name ) @configuration_points[ name ] end |
#configuration_point_count ⇒ Object
Returns the number of configuration points in the package.
179 180 181 |
# File 'lib/copland/package.rb', line 179 def configuration_point_count @configuration_points.size end |
#configuration_points ⇒ Object
Returns the names of all configuration points in the package.
138 139 140 |
# File 'lib/copland/package.rb', line 138 def configuration_points @configuration_points.keys.freeze end |
#each_configuration_point(&block) ⇒ Object
Iterates over each configuration point in the package.
164 165 166 |
# File 'lib/copland/package.rb', line 164 def each_configuration_point( &block ) @configuration_points.each_value( &block ) end |
#each_schema(&block) ⇒ Object
Iterates over each schema in the package.
169 170 171 |
# File 'lib/copland/package.rb', line 169 def each_schema( &block ) @schemas.each_value( &block ) end |
#each_service_point(&block) ⇒ Object
Iterates over each service point in the package.
158 159 160 161 |
# File 'lib/copland/package.rb', line 158 def each_service_point( &block ) @service_points.each_value( &block ) self end |
#find_schema(name) ⇒ Object
This is a convenience method for returning a schema with the given name, giving preference when a package is not specified to the schemas within the current package.
119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/copland/package.rb', line 119 def find_schema( name ) find_service( name ) do |pkg, id| if pkg.nil? raise PackageNotFound, name else schema = pkg.schema( id ) raise SchemaNotFound, name unless schema return schema end end end |
#find_service(name, &block) ⇒ Object
This is a convenience method for returning a service with the given name, giving preference when a package is not specified to the service points within the current package.
112 113 114 |
# File 'lib/copland/package.rb', line 112 def find_service( name, &block ) Copland::get_possibly_local_service( registry, self, name, &block ) end |
#fixate! ⇒ Object
Fixates the package. This will, in turn, fixate each configuration and service point in the package. Also, all pending contributions will be contributed to the configuration points they were intended for.
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/copland/package.rb', line 191 def fixate! extend Fixated @schemas.each_value { |schema| schema.fixate! } @service_points.each_value { |point| point.fixate! } @configuration_points.each_value { |point| point.fixate! } if @pending_contributions @pending_contributions.each do |value| name = value[ :name ] contribution = value[ :value ] configuration_point = find_service( name ) do |pkg, id| raise PackageNotFound, name unless pkg pkg.configuration_point( id ) end raise ConfigurationPointNotFound, name unless configuration_point contribution.instance_variable_set( :@contributor, self ) configuration_point.contribute contribution end remove_instance_variable :@pending_contributions end end |
#fixated? ⇒ Boolean
Returns false
, although when the package is fixated this will be overridden with a method that will return true
.
220 221 222 |
# File 'lib/copland/package.rb', line 220 def fixated? false end |
#schema(name) ⇒ Object
Returns the schema with the given name, or nil
if no such schema exists.
144 145 146 |
# File 'lib/copland/package.rb', line 144 def schema( name ) @schemas[ name ] end |
#schema_count ⇒ Object
Returns the number of schemas in the package.
184 185 186 |
# File 'lib/copland/package.rb', line 184 def schema_count @schemas.size end |
#service(name, &init) ⇒ Object
This instantiates the service point with the given name and returns the resulting service. If the service point does not exist, this will raise a ServicePointNotFound exception.
If a block is given, it will be used to initialize the service (but only when the service is created–if the service is a singleton service and it was created previously, the init block will be ignored).
98 99 100 101 |
# File 'lib/copland/package.rb', line 98 def service( name, &init ) point = service_point( name ) or raise ServicePointNotFound, name point.instance( &init ) end |
#service_exist?(name) ⇒ Boolean
Returns true
if the named service exists in this package, and false
otherwise.
105 106 107 |
# File 'lib/copland/package.rb', line 105 def service_exist?( name ) return !service_point( name ).nil? end |
#service_point(name) ⇒ Object
Returns the service point with the given name. If no such service point exists, this returns nil
.
82 83 84 |
# File 'lib/copland/package.rb', line 82 def service_point( name ) @service_points[ name ] end |
#service_point_count ⇒ Object
Returns the number of service points in the package.
174 175 176 |
# File 'lib/copland/package.rb', line 174 def service_point_count @service_points.size end |
#service_points ⇒ Object
This returns the names of all service points in the package.
87 88 89 |
# File 'lib/copland/package.rb', line 87 def service_points @service_points.keys.freeze end |