Class: ActiveFacts::Generators::Helpers::OO
Overview
Base class for generators of object-oriented class libraries for an ActiveFacts vocabulary.
Instance Method Summary
collapse
#build_entity_dependencies, #constraint_sort_key, #data_type_dump, #derivation_precursors_complete, #describe_fact_type, #describe_role_sequence, #describe_roles, #entity_types_dump, #fact_instances_dump, #fact_type_dump, #fact_type_dump_with_dependents, #fact_type_key, #fact_types_dump, #generate, #identified_by, #initialize, #non_subtype_dump, #print, #puts, #released_fact_types_dump, #role_ref_key, #set_option, #subtype_dump, #unit_dump, #units_banner, #units_dump, #units_end, #value_type_chain_dump, #value_type_dump, #value_type_fork, #value_types_dump, #vocabulary_end, #vocabulary_start
Instance Method Details
#append_ring_to_reading(reading, ring) ⇒ Object
137
138
139
|
# File 'lib/activefacts/generators/helpers/oo.rb', line 137
def append_ring_to_reading(reading, ring)
end
|
#constraint_banner ⇒ Object
147
148
149
|
# File 'lib/activefacts/generators/helpers/oo.rb', line 147
def constraint_banner
end
|
#constraint_dump(c) ⇒ Object
155
156
157
|
# File 'lib/activefacts/generators/helpers/oo.rb', line 155
def constraint_dump(c)
end
|
#constraint_end ⇒ Object
151
152
153
|
# File 'lib/activefacts/generators/helpers/oo.rb', line 151
def constraint_end
end
|
#constraints_dump ⇒ Object
17
18
19
|
# File 'lib/activefacts/generators/helpers/oo.rb', line 17
def constraints_dump
end
|
#entity_type_banner ⇒ Object
131
132
|
# File 'lib/activefacts/generators/helpers/oo.rb', line 131
def entity_type_banner
end
|
#entity_type_dump(o) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/activefacts/generators/helpers/oo.rb', line 27
def entity_type_dump(o)
o.ordered_dumped!
pi = o.preferred_identifier
supers = o.supertypes
if (supers.size > 0)
pi = nil if pi && pi.role_sequence.all_role_ref.detect{|rr| rr.role.fact_type.is_a?(ActiveFacts::Metamodel::TypeInheritance) }
subtype_dump(o, supers, pi)
else
non_subtype_dump(o, pi)
end
pi.ordered_dumped! if pi
end
|
#entity_type_group_end ⇒ Object
134
135
|
# File 'lib/activefacts/generators/helpers/oo.rb', line 134
def entity_type_group_end
end
|
#fact_roles_dump(fact_type) ⇒ Object
An objectified fact type has internal roles that are always “has_one”:
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/activefacts/generators/helpers/oo.rb', line 115
def fact_roles_dump(fact_type)
fact_type.all_role.sort_by{|role|
role.preferred_role_name(fact_type.entity_type)
}.each{|role|
role_name = role.preferred_role_name(fact_type.entity_type)
one_to_one = role.is_unique
as = role_name != role.object_type.oo_default_role_name ? "_as_#{role_name}" : ""
raise "Fact #{fact_type.describe} type is not objectified" unless fact_type.entity_type
other_role_method = (one_to_one ? "" : "all_") +
fact_type.entity_type.oo_default_role_name +
as
binary_dump(role, role_name, role.object_type, true, one_to_one, nil, nil, other_role_method)
}
end
|
#fact_type_banner ⇒ Object
141
142
|
# File 'lib/activefacts/generators/helpers/oo.rb', line 141
def fact_type_banner
end
|
#fact_type_end ⇒ Object
144
145
|
# File 'lib/activefacts/generators/helpers/oo.rb', line 144
def fact_type_end
end
|
#role_dump(role) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/activefacts/generators/helpers/oo.rb', line 57
def role_dump(role)
fact_type = role.fact_type
if fact_type.all_role.size == 1
unary_dump(role, role.preferred_role_name)
return
end
return if role.fact_type.entity_type
if fact_type.all_role.size != 2
return end
if fact_type.is_a?(ActiveFacts::Metamodel::TypeInheritance)
return
end
return unless role.is_functional
other_role = fact_type.all_role.select{|r| r != role}[0]
other_role_name = other_role.preferred_role_name
other_player = other_role.object_type
one_to_one = other_role.is_functional
return if one_to_one &&
!other_role.object_type.ordered_dumped
role_method = role.preferred_role_name
other_role_method = one_to_one ? role_method : "all_"+role_method
if other_role_name != other_player.oo_default_role_name and
role_method == role.object_type.oo_default_role_name
other_role_method += "_as_#{other_role_name}"
end
role_name = role_method
role_name = nil if role_name == role.object_type.oo_default_role_name
b = role.ruby_role_definition
puts b
end
|
#roles_dump(o) ⇒ Object
Dump the roles for an object type (excluding the roles of a fact type which is objectified)
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/activefacts/generators/helpers/oo.rb', line 43
def roles_dump(o)
o.all_role.
select{|role|
role.fact_type.all_role.size <= 2 &&
!role.fact_type.is_a?(ActiveFacts::Metamodel::LinkFactType)
}.
sort_by{|role|
other_role = role.fact_type.all_role.select{|r2| r2 != role}[0] || role
other_role.preferred_role_name(o) + ':' + role.preferred_role_name(other_role.object_type)
}.each{|role|
role_dump(role)
}
end
|
#skip_fact_type(f) ⇒ Object
108
109
110
111
112
|
# File 'lib/activefacts/generators/helpers/oo.rb', line 108
def skip_fact_type(f)
!f.entity_type ||
f.is_a?(ActiveFacts::Metamodel::TypeInheritance)
end
|
#value_type_banner ⇒ Object
21
22
|
# File 'lib/activefacts/generators/helpers/oo.rb', line 21
def value_type_banner
end
|
#value_type_end ⇒ Object
24
25
|
# File 'lib/activefacts/generators/helpers/oo.rb', line 24
def value_type_end
end
|