lib/copland/package.rb in copland-0.8.0 vs lib/copland/package.rb in copland-1.0.0
- old
+ new
@@ -76,36 +76,50 @@
schema.owner = self
@schemas[ schema.name ] = schema
end
# Returns the service point with the given name. If no such service point
- # exists, this returns +nil+.
- def service_point( name )
- @service_points[ name ]
+ # exists, this returns +nil+. If +include_private+ is false, then this will
+ # also return +nil+ if the point exists, but is marked private.
+ def service_point( name, include_private=false )
+ point = @service_points[ name ]
+ return nil if point.nil? || point.visibility == :private &&
+ !include_private
+ point
end
- # This returns the names of all service points in the package.
- def service_points
- @service_points.keys.freeze
+ # 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.
+ 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
# 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).
- def service( name, &init )
- point = service_point( name ) or raise ServicePointNotFound, name
+ #
+ # If +include_private+ is true, then only public service points may be
+ # instantiated.
+ def service( name, include_private=false, &init )
+ point = service_point( name, include_private ) or
+ raise ServicePointNotFound, name
point.instance( &init )
end
# Returns +true+ if the named service exists in this package, and +false+
# otherwise.
- def service_exist?( name )
- return !service_point( name ).nil?
+ def service_exist?( name, include_private=false )
+ return !service_point( name, include_private ).nil?
end
# 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.
@@ -153,12 +167,14 @@
( @pending_contributions ||= [] ).push :name => name,
:value => value
end
# Iterates over each service point in the package.
- def each_service_point( &block )
- @service_points.each_value( &block )
+ 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
# Iterates over each configuration point in the package.
def each_configuration_point( &block )
@@ -169,11 +185,13 @@
def each_schema( &block )
@schemas.each_value( &block )
end
# Returns the number of service points in the package.
- def service_point_count
- @service_points.size
+ def service_point_count( include_private=false )
+ @service_points.
+ reject { |k,v| v.visibility == :private && !include_private }.
+ size
end
# Returns the number of configuration points in the package.
def configuration_point_count
@configuration_points.size