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(include_private = false, &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, include_private = false, &init) ⇒ Object
This instantiates the service point with the given name and returns the resulting service.
-
#service_exist?(name, include_private = false) ⇒ Boolean
Returns
true
if the named service exists in this package, andfalse
otherwise. -
#service_point(name, include_private = false) ⇒ Object
Returns the service point with the given name.
-
#service_point_count(include_private = false) ⇒ Object
Returns the number of service points in the package.
-
#service_points(include_private = false) ⇒ 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.
166 167 168 169 |
# File 'lib/copland/package.rb', line 166 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.
147 148 149 |
# File 'lib/copland/package.rb', line 147 def configuration_point( name ) @configuration_points[ name ] end |
#configuration_point_count ⇒ Object
Returns the number of configuration points in the package.
197 198 199 |
# File 'lib/copland/package.rb', line 197 def configuration_point_count @configuration_points.size end |
#configuration_points ⇒ Object
Returns the names of all configuration points in the package.
152 153 154 |
# File 'lib/copland/package.rb', line 152 def configuration_points @configuration_points.keys.freeze end |
#each_configuration_point(&block) ⇒ Object
Iterates over each configuration point in the package.
180 181 182 |
# File 'lib/copland/package.rb', line 180 def each_configuration_point( &block ) @configuration_points.each_value( &block ) end |
#each_schema(&block) ⇒ Object
Iterates over each schema in the package.
185 186 187 |
# File 'lib/copland/package.rb', line 185 def each_schema( &block ) @schemas.each_value( &block ) end |
#each_service_point(include_private = false, &block) ⇒ Object
Iterates over each service point in the package.
172 173 174 175 176 177 |
# File 'lib/copland/package.rb', line 172 def each_service_point( include_private=false, &block ) @service_points.each_value do |pt| yield pt if pt.visibility == :public || include_private end 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.
133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/copland/package.rb', line 133 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.
126 127 128 |
# File 'lib/copland/package.rb', line 126 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.
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/copland/package.rb', line 209 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
.
238 239 240 |
# File 'lib/copland/package.rb', line 238 def fixated? false end |
#schema(name) ⇒ Object
Returns the schema with the given name, or nil
if no such schema exists.
158 159 160 |
# File 'lib/copland/package.rb', line 158 def schema( name ) @schemas[ name ] end |
#schema_count ⇒ Object
Returns the number of schemas in the package.
202 203 204 |
# File 'lib/copland/package.rb', line 202 def schema_count @schemas.size end |
#service(name, include_private = false, &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).
If include_private
is true, then only public service points may be instantiated.
111 112 113 114 115 |
# File 'lib/copland/package.rb', line 111 def service( name, include_private=false, &init ) point = service_point( name, include_private ) or raise ServicePointNotFound, name point.instance( &init ) end |
#service_exist?(name, include_private = false) ⇒ Boolean
Returns true
if the named service exists in this package, and false
otherwise.
119 120 121 |
# File 'lib/copland/package.rb', line 119 def service_exist?( name, include_private=false ) return !service_point( name, include_private ).nil? end |
#service_point(name, include_private = false) ⇒ Object
Returns the service point with the given name. If no such service point exists, this returns nil
. If include_private
is false, then this will also return nil
if the point exists, but is marked private.
83 84 85 86 87 88 |
# File 'lib/copland/package.rb', line 83 def service_point( name, include_private=false ) point = @service_points[ name ] return nil if point.nil? || point.visibility == :private && !include_private point end |
#service_point_count(include_private = false) ⇒ Object
Returns the number of service points in the package.
190 191 192 193 194 |
# File 'lib/copland/package.rb', line 190 def service_point_count( include_private=false ) @service_points. reject { |k,v| v.visibility == :private && !include_private }. size end |
#service_points(include_private = false) ⇒ Object
This returns the names of all service points in the package. If include_private
is true (the default), then only the public service points will be returned.
93 94 95 96 97 98 99 |
# File 'lib/copland/package.rb', line 93 def service_points( include_private=false ) names = @service_points.keys.dup if !include_private names.reject! { |p| @service_points[p].visibility != :public } end names end |