Class: ActiveFacts::Metamodel::Vocabulary

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

Instance Method Summary collapse

Instance Method Details

#check_valid_nonexistent_object_type_name(name) ⇒ Object

This name does not yet exist (at least not as we expect it to). If it in fact does exist (but as the wrong type), complain. If it doesn’t exist, but its name would cause existing fact type readings to be re-interpreted to a different meaning, complain. Otherwise return nil.



28
29
30
31
32
# File 'lib/activefacts/metamodel/extensions.rb', line 28

def check_valid_nonexistent_object_type_name name
  if ot = valid_object_type_name(name)
    raise "Cannot redefine #{ot.class.basename} #{name}"
  end
end

#finaliseObject



13
14
15
16
17
18
19
20
21
# File 'lib/activefacts/metamodel/extensions.rb', line 13

def finalise
  constellation.FactType.values.each do |fact_type|
    if c = fact_type.check_and_add_spanning_uniqueness_constraint
      trace :constraint, "Checking for existence of at least one uniqueness constraint over the roles of #{fact_type.default_reading.inspect}"
      fact_type.check_and_add_spanning_uniqueness_constraint = nil
      c.call
    end
  end
end

#object_type_lookup(name) ⇒ Object



71
72
73
# File 'lib/activefacts/metamodel/extensions.rb', line 71

def object_type_lookup name
  @constellation.ObjectType[[identifying_role_values, name]]
end

#valid_entity_type_name(name) ⇒ Object

If this entity type exists, ok, otherwise check it’s ok to add it



60
61
62
63
# File 'lib/activefacts/metamodel/extensions.rb', line 60

def valid_entity_type_name name
  @constellation.EntityType[[identifying_role_values, name]] or
    check_valid_nonexistent_object_type_name name
end

#valid_object_type_name(name) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/activefacts/metamodel/extensions.rb', line 34

def valid_object_type_name name
  # Raise an exception if adding this name to the vocabulary would create anomalies
  anomaly = constellation.Reading.detect do |r_key, reading|
      expanded = reading.expand do |role_ref, *words|
          words.map! do |w|
            case
            when w == nil
              w
            when w[0...name.size] == name
              '_ok_'+w
            when w[-name.size..-1] == name
              w[-1]+'_ok_'
            else
              w
            end
          end

          words
        end
      expanded =~ %r{\b#{name}\b}
    end
  raise "Adding new term '#{name}' would create anomalous re-interpretation of '#{anomaly.expand}'" if anomaly
  @constellation.ObjectType[[identifying_role_values, name]]
end

#valid_value_type_name(name) ⇒ Object

If this entity type exists, ok, otherwise check it’s ok to add it



66
67
68
69
# File 'lib/activefacts/metamodel/extensions.rb', line 66

def valid_value_type_name name
  @constellation.ValueType[[identifying_role_values, name]] or
    check_valid_nonexistent_object_type_name name
end