lib/activefacts/vocabulary/extensions.rb in activefacts-0.7.0 vs lib/activefacts/vocabulary/extensions.rb in activefacts-0.7.1

- old
+ new

@@ -1,9 +1,11 @@ # -# Extensions to the ActiveFacts Vocabulary API (which is generated from the Metamodel) -# Copyright (c) 2008 Clifford Heath. Read the LICENSE file. +# ActiveFacts Vocabulary Metamodel. +# Extensions to the ActiveFacts Vocabulary classes (which are generated from the Metamodel) # +# Copyright (c) 2009 Clifford Heath. Read the LICENSE file. +# module ActiveFacts module Metamodel class FactType def all_reading_by_ordinal @@ -110,21 +112,21 @@ def supertypes_transitive [self] + (supertype ? supertype.supertypes_transitive : []) end def subtypes - all_value_type_by_supertype + all_value_type_as_supertype end end class EntityType include ActiveFacts def preferred_identifier if fact_type # For a nested fact type, the PI is a unique constraint over N or N-1 roles - fact_roles = fact_type.all_role + fact_roles = Array(fact_type.all_role) debug :pi, "Looking for PI on nested fact type #{name}" do pi = catch :pi do fact_roles[0,2].each{|r| # Try the first two roles of the fact type, that's enough r.all_role_ref.map{|rr| # All role sequences that reference this role role_sequence = rr.role_sequence @@ -169,11 +171,11 @@ pi = catch :pi do all_supertypes = supertypes_transitive debug :pi, "PI roles must be played by one of #{all_supertypes.map(&:name)*", "}" if all_supertypes.size > 1 all_role.each{|role| next unless role.unique || fact_type - ftroles = role.fact_type.all_role + ftroles = Array(role.fact_type.all_role) # Skip roles in ternary and higher fact types, they're objectified, and in unaries, they can't identify us. next if ftroles.size != 2 debug :pi, "Considering role in #{role.fact_type.describe(role)}" @@ -260,15 +262,15 @@ end # An array of all direct subtypes: def subtypes # REVISIT: There's no sorting here. Should there be? - all_type_inheritance_by_supertype.map{|ti| ti.subtype } + all_type_inheritance_as_supertype.map{|ti| ti.subtype } end def all_supertype_inheritance - all_type_inheritance_by_subtype.sort_by{|ti| + all_type_inheritance_as_subtype.sort_by{|ti| [ti.provides_identification ? 0 : 1, ti.supertype.name] } end # An array all direct supertypes @@ -278,20 +280,20 @@ } end # An array of self followed by all supertypes in order: def supertypes_transitive - ([self] + all_type_inheritance_by_subtype.map{|ti| + ([self] + all_type_inheritance_as_subtype.map{|ti| # debug ti.class.roles.verbalise; exit ti.supertype.supertypes_transitive }).flatten.uniq end # A subtype does not have a identifying_supertype if it defines its own identifier def identifying_supertype debug "Looking for identifying_supertype of #{name}" - all_type_inheritance_by_subtype.detect{|ti| + all_type_inheritance_as_subtype.detect{|ti| debug "considering supertype #{ti.supertype.name}" next unless ti.provides_identification debug "found identifying supertype of #{name}, it's #{ti.supertype.name}" return ti.supertype } @@ -354,10 +356,10 @@ reading_text. scan(/(?: |\{[0-9]+\}|[^{} ]+)/). # split up the text into words reject{|s| s==' '}. # Remove white space map do |frag| # and go through the bits if frag =~ /\{([0-9]+)\}/ - role_sequence.all_role_ref[$1.to_i] + role_sequence.all_role_ref.detect{|rr| rr.ordinal == $1.to_i} else frag end end end