class ActiveFacts::Metamodel::Role
Public Instance Methods
all_constraint()
click to toggle source
return an array of all the constraints on this role (not including ValueConstraint
on a ValueType
player)
# File lib/activefacts/metamodel/extensions.rb, line 381 def all_constraint ( Array(role_value_constraint) + all_role_ref.to_a.flat_map do |rr| rr.role_sequence.all_presence_constraint.to_a + rr.role_sequence.all_subset_constraint_as_superset_role_sequence + rr.role_sequence.all_subset_constraint_as_subset_role_sequence + rr.role_sequence.all_set_comparison_roles.map(&:set_comparison_constraint) end + all_ring_constraint.to_a + all_ring_constraint_as_other_role.to_a ).uniq end
base_role()
click to toggle source
counterpart()
click to toggle source
# File lib/activefacts/metamodel/extensions.rb, line 369 def counterpart case fact_type.all_role.size when 1 self when 2 (fact_type.all_role.to_a-[self])[0] else nil # raise "counterpart roles are undefined in n-ary fact types" end end
describe(highlight = nil)
click to toggle source
# File lib/activefacts/metamodel/extensions.rb, line 277 def describe(highlight = nil) object_type.name + (self == highlight ? "*" : "") end
is_functional()
click to toggle source
Return true if this role is functional (has only one instance wrt its player) A role in an objectified fact type is deemed to refer to the implicit role of the objectification.
# File lib/activefacts/metamodel/extensions.rb, line 298 def is_functional return true if fact_type.is_a?(LinkFactType) # Handle objectification roles fact_type.entity_type or fact_type.all_role.size != 2 or uniqueness_constraint end
is_identifying()
click to toggle source
# File lib/activefacts/metamodel/extensions.rb, line 318 def is_identifying uc = uniqueness_constraint and uc.is_preferred_identifier end
is_link_role()
click to toggle source
# File lib/activefacts/metamodel/extensions.rb, line 357 def is_link_role fact_type.is_a?(LinkFactType) end
is_mandatory()
click to toggle source
# File lib/activefacts/metamodel/extensions.rb, line 281 def is_mandatory return true if fact_type.is_a?(LinkFactType) # Handle objectification roles all_role_ref.detect{|rr| rs = rr.role_sequence rs.all_role_ref.size == 1 and rs.all_presence_constraint.detect{|pc| pc.min_frequency and pc.min_frequency >= 1 and pc.is_mandatory } } ? true : false end
is_mirror_role()
click to toggle source
# File lib/activefacts/metamodel/extensions.rb, line 361 def is_mirror_role is_a?(MirrorRole) end
is_objectification_role()
click to toggle source
# File lib/activefacts/metamodel/extensions.rb, line 365 def is_objectification_role is_link_role && !is_mirror_role end
is_unique()
click to toggle source
Is there are internal uniqueness constraint on this role only?
# File lib/activefacts/metamodel/extensions.rb, line 323 def is_unique return true if fact_type.is_a?(LinkFactType) or # Handle objectification roles fact_type.all_role.size == 1 # and unary roles uniqueness_constraint ? true : false end
name()
click to toggle source
# File lib/activefacts/metamodel/extensions.rb, line 334 def name role_name or is_mirror_role && base_role.role_name or fact_type.is_unary && unary_name or String::Words.new(preferred_reference.role_name nil).capwords*' ' or object_type.name end
preferred_reference()
click to toggle source
# File lib/activefacts/metamodel/extensions.rb, line 292 def preferred_reference fact_type.preferred_reading.role_sequence.all_role_ref.detect{|rr| rr.role == self } end
unary_name()
click to toggle source
# File lib/activefacts/metamodel/extensions.rb, line 342 def unary_name fact_type. preferred_reading. text. gsub(/(.*)\{[0-9]\}(.*)/) do if $1.empty? or $2.empty? "#{$1} #{$2}" else "#{$1} #{object_type.name} #{$2}" end end. words. titlewords*' ' end
unique()
click to toggle source
# File lib/activefacts/metamodel/extensions.rb, line 330 def unique raise "REVISIT: unique is deprecated. Call is_unique instead" end
uniqueness_constraint()
click to toggle source
Find any internal uniqueness constraint on this role only
# File lib/activefacts/metamodel/extensions.rb, line 307 def uniqueness_constraint base_role.all_role_ref.detect{|rr| rs = rr.role_sequence rs.all_role_ref.size == 1 and rs.all_presence_constraint.detect do |pc| return pc if pc.max_frequency == 1 and !pc.enforcement # Alethic uniqueness constraint end } nil end