Class: ActiveFacts::Generate::OO
Overview
Base class for generators of object-oriented class libraries for an ActiveFacts vocabulary.
Direct Known Subclasses
RUBY
Instance Method Summary
collapse
#build_entity_dependencies, #build_indices, #constraint_sort_key, #describe_fact_type, #describe_role_sequence, #describe_roles, #entity_type_dump, #entity_types_dump, #expanded_reading, #fact_instances_dump, #fact_readings_with_constraints, #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, #show_frequency, #subtype_dump, #value_type_dump, #value_types_dump, #vocabulary_end, #vocabulary_start
Instance Method Details
#append_ring_to_reading(reading, ring) ⇒ Object
154
155
156
|
# File 'lib/activefacts/generate/oo.rb', line 154
def append_ring_to_reading(reading, ring)
end
|
#constraint_banner ⇒ Object
164
165
166
|
# File 'lib/activefacts/generate/oo.rb', line 164
def constraint_banner
end
|
#constraint_dump(c) ⇒ Object
172
173
174
|
# File 'lib/activefacts/generate/oo.rb', line 172
def constraint_dump(c)
end
|
#constraint_end ⇒ Object
168
169
170
|
# File 'lib/activefacts/generate/oo.rb', line 168
def constraint_end
end
|
#constraints_dump(constraints_used) ⇒ Object
16
17
18
|
# File 'lib/activefacts/generate/oo.rb', line 16
def constraints_dump(constraints_used)
end
|
#entity_type_banner ⇒ Object
148
149
|
# File 'lib/activefacts/generate/oo.rb', line 148
def entity_type_banner
end
|
#entity_type_group_end ⇒ Object
151
152
|
# File 'lib/activefacts/generate/oo.rb', line 151
def entity_type_group_end
end
|
#fact_roles_dump(fact) ⇒ Object
An objectified fact type has internal roles that are always “has_one”:
136
137
138
139
140
141
142
143
144
145
146
|
# File 'lib/activefacts/generate/oo.rb', line 136
def fact_roles_dump(fact)
fact.all_role.sort_by{|role|
preferred_role_name(role)
}.each{|role|
role_name = preferred_role_name(role)
as = role_name != role.concept.name.snakecase ? "_as_#{role_name}" : ""
raise "Fact #{fact.describe} type is not objectified" unless fact.entity_type
other_role_method = "all_"+fact.entity_type.name.snakecase+as
binary_dump(role, role_name, role.concept, false, nil, nil, other_role_method)
}
end
|
#fact_type_banner ⇒ Object
158
159
|
# File 'lib/activefacts/generate/oo.rb', line 158
def fact_type_banner
end
|
#fact_type_end ⇒ Object
161
162
|
# File 'lib/activefacts/generate/oo.rb', line 161
def fact_type_end
end
|
#preferred_role_name(role) ⇒ Object
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/activefacts/generate/oo.rb', line 97
def preferred_role_name(role)
return "" if TypeInheritance === role.fact_type
reading = role.fact_type.preferred_reading
preferred_role_ref = reading.role_sequence.all_role_ref.detect{|reading_rr|
reading_rr.role == role
}
if (role.fact_type.all_role.size == 1)
return (role.role_name && role.role_name.snakecase) ||
reading.reading_text.gsub(/ *\{0\} */,'').gsub(' ','_').downcase
end
role_words = []
role_name = role.role_name
role_name = nil if role_name == ""
la = preferred_role_ref.leading_adjective
role_words << la.gsub(/ /,'_') if la && la != "" and !role.role_name
role_words << (role_name || role.concept.name)
ta = preferred_role_ref.trailing_adjective
role_words << ta.gsub(/ /,'_') if ta && ta != "" and !role_name
n = role_words.map{|w| w.gsub(/([a-z])([A-Z]+)/,'\1_\2').downcase}*"_"
n
end
|
#role_dump(role) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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
|
# File 'lib/activefacts/generate/oo.rb', line 38
def role_dump(role)
fact_type = role.fact_type
if fact_type.all_role.size == 1
unary_dump(role, preferred_role_name(role))
return
elsif fact_type.all_role.size != 2
return end
if TypeInheritance === fact_type
return
end
other_role = fact_type.all_role.select{|r| r != role}[0]
other_role_name = preferred_role_name(other_role)
other_player = other_role.concept
fact_constraints = @presence_constraints_by_fact[fact_type]
ucs = fact_constraints.select{|c| PresenceConstraint === c && c.max_frequency == 1 }
unless ucs.find {|c|
roles = c.role_sequence.all_role_ref.map(&:role)
roles == [role]
}
return
end
if ucs.find {|c| c.role_sequence.all_role_ref.map(&:role) == [other_role] } &&
!@concept_types_dumped[other_role.concept]
return
end
one_to_one = ucs.find {|c| c.role_sequence.all_role_ref.map(&:role) == [other_role] }
role_method = preferred_role_name(role)
as = other_role_name != other_player.name.snakecase ? "_as_#{other_role_name}" : ""
other_role_method = one_to_one ? role_method : "all_"+role_method
if other_role_name != other_player.name.snakecase and
role_method == role.concept.name.snakecase
other_role_method += "_as_#{other_role_name}"
end
role_name = role_method
role_name = nil if role_name == role.concept.name.snakecase
binary_dump(role, other_role_name, other_player, one_to_one, nil, role_name, other_role_method)
end
|
#roles_dump(o) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/activefacts/generate/oo.rb', line 26
def roles_dump(o)
o.all_role.
select{|role|
role.fact_type.all_role.size <= 2
}.
sort_by{|role|
preferred_role_name(role.fact_type.all_role.select{|r2| r2 != role}[0] || role)
}.each{|role|
role_dump(role)
}
end
|
#skip_fact_type(f) ⇒ Object
129
130
131
132
133
|
# File 'lib/activefacts/generate/oo.rb', line 129
def skip_fact_type(f)
!f.entity_type ||
TypeInheritance === f
end
|
#value_type_banner ⇒ Object
20
21
|
# File 'lib/activefacts/generate/oo.rb', line 20
def value_type_banner
end
|
#value_type_end ⇒ Object
23
24
|
# File 'lib/activefacts/generate/oo.rb', line 23
def value_type_end
end
|