Class: ActiveFacts::Metamodel::Role
- Inherits:
-
Object
- Object
- ActiveFacts::Metamodel::Role
- Defined in:
- lib/activefacts/persistence/tables.rb,
lib/activefacts/vocabulary/metamodel.rb,
lib/activefacts/vocabulary/extensions.rb
Overview
EntityType class
Instance Method Summary collapse
- #describe(highlight = nil) ⇒ Object
- #is_mandatory ⇒ Object
-
#preferred_reference ⇒ Object
Return the RoleRef to this role from its fact type’s preferred_reading.
-
#role_type ⇒ Object
:nodoc:.
-
#unique ⇒ Object
Is there are internal uniqueness constraint on this role only?.
Instance Method Details
#describe(highlight = nil) ⇒ Object
59 60 61 |
# File 'lib/activefacts/vocabulary/extensions.rb', line 59 def describe(highlight = nil) concept.name + (self == highlight ? "*" : "") end |
#is_mandatory ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/activefacts/vocabulary/extensions.rb', line 74 def is_mandatory 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 |
#preferred_reference ⇒ Object
Return the RoleRef to this role from its fact type’s preferred_reading
85 86 87 |
# File 'lib/activefacts/vocabulary/extensions.rb', line 85 def preferred_reference fact_type.preferred_reading.role_sequence.all_role_ref.detect{|rr| rr.role == self } end |
#role_type ⇒ Object
:nodoc:
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/activefacts/persistence/tables.rb', line 113 def role_type # TypeInheritance roles are always 1:1 if TypeInheritance === fact_type return concept == fact_type.supertype ? :supertype : :subtype end # Always N:1 if unary: return :unary if fact_type.all_role.size == 1 # List the UCs on this fact type: all_uniqueness_constraints = fact_type.all_role.map do |fact_role| fact_role.all_role_ref.map do |rr| rr.role_sequence.all_presence_constraint.select do |pc| pc.max_frequency == 1 end end end.flatten.uniq to_1 = all_uniqueness_constraints. detect do |c| (rr = c.role_sequence.all_role_ref.single) and rr.role == self end if fact_type.entity_type # This is a role in an objectified fact type from_1 = true else # It's to-1 if a UC exists over roles of this FT that doesn't cover this role: from_1 = all_uniqueness_constraints.detect{|uc| !uc.role_sequence.all_role_ref.detect{|rr| rr.role == self || rr.role.fact_type != fact_type} } end if from_1 return to_1 ? :one_one : :one_many else return to_1 ? :many_one : :many_many end end |
#unique ⇒ Object
Is there are internal uniqueness constraint on this role only?
64 65 66 67 68 69 70 71 72 |
# File 'lib/activefacts/vocabulary/extensions.rb', line 64 def unique all_role_ref.detect{|rr| rs = rr.role_sequence rs.all_role_ref.size == 1 and rs.all_presence_constraint.detect{|pc| pc.max_frequency == 1 } } ? true : false end |