Class: ActiveFacts::Metamodel::Concept

Inherits:
Object
  • Object
show all
Defined in:
lib/activefacts/metamodel/metamodel.rb,
lib/activefacts/metamodel/extensions.rb

Instance Method Summary collapse

Instance Method Details

#describeObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/activefacts/metamodel/extensions.rb', line 77

def describe
  case
  when object_type; "#{object_type.class.basename} #{object_type.name.inspect}"
  when fact_type; "FactType #{fact_type.default_reading.inspect}"
  when role; "Role in #{role.fact_type.describe(role)}"
  when constraint; constraint.describe
  when instance; "Instance #{instance.verbalise}"
  when fact; "Fact #{fact.verbalise}"
  when query; query.describe
  when context_note; "ContextNote#{context_note.verbalise}"
  when unit; "Unit #{unit.describe}"
  when population; "Population: #{population.name}"
  when transform_rule; "Transform Rule: #{transform_rule.describe}"
  else
    raise "ROGUE CONCEPT OF NO TYPE"
  end
end

#embodied_asObject



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/activefacts/metamodel/extensions.rb', line 95

def embodied_as
  case
  when object_type; object_type
  when fact_type; fact_type
  when role; role
  when constraint; constraint
  when instance; instance
  when fact; fact
  when query; query
  when context_note; context_note
  when unit; unit
  when population; population
  when transform_rule; transform_rule
  else
    raise "ROGUE CONCEPT OF NO TYPE"
  end
end

#precursorsObject

Return an array of all Concepts that must be defined before this concept can be defined:



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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/activefacts/metamodel/extensions.rb', line 114

def precursors
  case body = embodied_as
  when ActiveFacts::Metamodel::ValueType
    [ body.supertype, body.unit ] +
    body.all_value_type_parameter.map{|f| f.facet_value_type } +
    body.all_value_type_parameter_restriction.map{|vr| vr.value.unit}
  when ActiveFacts::Metamodel::EntityType
    # You can't define the preferred_identifier fact types until you define the entity type,
    # but the objects which play the identifying roles must be defined:
    body.preferred_identifier.role_sequence.all_role_ref.map {|rr| rr.role.object_type } +
    # You can't define the objectified fact type until you define the entity type:
    # [ body.fact_type ]  # If it's an objectification
    body.all_type_inheritance_as_subtype.map{|ti| ti.supertype}   # If it's a subtype
  when FactType
    body.all_role.map(&:object_type)
  when Role   # We don't consider roles as they cannot be separately defined
    []
  when ActiveFacts::Metamodel::PresenceConstraint
    body.role_sequence.all_role_ref.map do |rr|
      rr.role.fact_type
    end
  when ActiveFacts::Metamodel::ValueConstraint
    [ body.role_as_role_value_constraint ? body.role_as_role_value_constraint.fact_type : nil, body.value_type ] +
    body.all_allowed_range.map do |ar|
      [ ar.value_range.minimum_bound, ar.value_range.maximum_bound ].compact.map{|b| b.value.unit}
    end
  when ActiveFacts::Metamodel::SubsetConstraint
    body.subset_role_sequence.all_role_ref.map{|rr| rr.role.fact_type } +
    body.superset_role_sequence.all_role_ref.map{|rr| rr.role.fact_type }
  when ActiveFacts::Metamodel::SetComparisonConstraint
    body.all_set_comparison_roles.map{|scr| scr.role_sequence.all_role_ref.map{|rr| rr.role.fact_type } }
  when ActiveFacts::Metamodel::RingConstraint
    [ body.role.fact_type, body.other_role.fact_type ]
  when Instance
    [ body.population, body.object_type, body.value ? body.value.unit : nil ]
  when Fact
    [ body.population, body.fact_type ]
  when Query
    body.all_variable.map do |v|
      [ v.object_type,
        v.value ? v.value.unit : nil,
        v.step ? v.step.fact_type : nil
      ] +
      v.all_play.map{|p| p.role.fact_type }
    end
  when ContextNote
    []
  when Unit
    body.all_derivation_as_derived_unit.map{|d| d.base_unit }
  when Population
    []
  else
    raise "ROGUE CONCEPT OF NO TYPE"
  end.flatten.compact.uniq.map{|c| c.concept }
end