lib/activefacts/api/constellation.rb in activefacts-0.7.0 vs lib/activefacts/api/constellation.rb in activefacts-0.7.1

- old
+ new

@@ -1,12 +1,14 @@ # -# The ActiveFacts Runtime API Constellation class -# Copyright (c) 2008 Clifford Heath. Read the LICENSE file. +# ActiveFacts Runtime API +# Constellation class # +# Copyright (c) 2009 Clifford Heath. Read the LICENSE file. +# module ActiveFacts - module API + module API #:nodoc: # A Constellation is a population of instances of the Concept classes of a Vocabulary. # Every concept class is either a Value type or an Entity type. # # Value types are uniquely identified by their value, and a constellation will only # ever have a single instance of a given value of that class. @@ -35,11 +37,11 @@ # Can also say c.MyClass.each{|k, v| ... } # Create a new empty Constellation over the given Vocabulary def initialize(vocabulary) @vocabulary = vocabulary - @instances = Hash.new{|h,k| h[k] = {} } + @instances = Hash.new{|h,k| h[k] = InstanceIndex.new } end def inspect #:nodoc: "Constellation:#{object_id}" end @@ -50,11 +52,11 @@ ([instance.class]+instance.class.supertypes_transitive).each do |klass| @instances[klass].delete_if{|k,v| v == instance } end end - # With parameters, assert an instance of the concept whose name is the missing method. + # With parameters, assert an instance of the concept whose name is the missing method, identified by the values passed as *args*. # With no parameters, return the collection of all instances of that concept. def method_missing(m, *args) if klass = @vocabulary.const_get(m) if args.size == 0 # Return the collection of all instances of this class in the constellation: @@ -75,10 +77,10 @@ vocabulary.concept.keys.sort.map{|concept| klass = vocabulary.const_get(concept) # REVISIT: It would be better not to rely on the role name pattern here: single_roles, multiple_roles = klass.roles.keys.sort_by(&:to_s).partition{|r| r.to_s !~ /\Aall_/ } - single_roles -= klass.identifying_roles if (klass.respond_to?(:identifying_roles)) + single_roles -= klass.identifying_role_names if (klass.respond_to?(:identifying_role_names)) # REVISIT: Need to include superclass roles also. instances = send(concept.to_sym) next nil unless instances.size > 0 "\tEvery #{concept}:\n" +