Module: ActiveFacts::Generators::ScalaTraits::EntityType
- Defined in:
- lib/activefacts/generators/traits/scala.rb
Instance Method Summary collapse
- #id_role_names(id_roles) ⇒ Object
- #id_role_types(id_roles) ⇒ Object
- #scala_metamodel(title_name) ⇒ Object
- #scala_object(title_name, id_names, id_types) ⇒ Object
- #scala_objectification ⇒ Object
- #scala_objectification_metamodel ⇒ Object
- #scala_shared(o, supertypes, pi = nil) ⇒ Object
- #scala_trait(title_name, primary_supertype, pis) ⇒ Object
Instance Method Details
#id_role_names(id_roles) ⇒ Object
335 336 337 338 339 340 341 |
# File 'lib/activefacts/generators/traits/scala.rb', line 335 def id_role_names id_roles id_roles.map do |role| # Ignore identification through a supertype next if role.fact_type.kind_of?(ActiveFacts::Metamodel::TypeInheritance) role.scala_preferred_role_name(self).words.camelcase end.compact end |
#id_role_types(id_roles) ⇒ Object
343 344 345 346 347 348 349 350 351 352 |
# File 'lib/activefacts/generators/traits/scala.rb', line 343 def id_role_types id_roles id_roles.map do |role| next if role.fact_type.kind_of?(ActiveFacts::Metamodel::TypeInheritance) if !role.fact_type.entity_type && role.fact_type.all_role.size == 1 "Boolean" else role.object_type.name.words.titlecase end end.compact end |
#scala_metamodel(title_name) ⇒ Object
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/activefacts/generators/traits/scala.rb', line 296 def (title_name) pi = preferred_identifier # The following finds the closest non-inheritance identifier #while pi.role_sequence.all_role_ref.size == 1 and # (role = pi.role_sequence.all_role_ref.single.role).fact_type.is_a?(ActiveFacts::Metamodel::TypeInheritance) # pi = role.fact_type.supertype_role.object_type.preferred_identifier #end = pi.role_sequence.all_role_ref_in_order.map{|rr| rr.role.object_type.name.words.camelcase }*', ' supertypes_list = if supertypes.empty? 'Nil' else "List(#{supertypes.map{|s| s.name.words.camelcase}*', '})" end " val #{name.words.camelcase} = assertEntity(FBMModel.EntityType(FBMModel.DomainObjectTypeName(\"#{title_name}\"), #{supertypes_list}, Seq(#{})))\n" end |
#scala_object(title_name, id_names, id_types) ⇒ Object
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/activefacts/generators/traits/scala.rb', line 248 def scala_object(title_name, id_names, id_types) " object #{title_name} {\n" + " def apply(" + (id_names.zip(id_types).map do |(name, type_name)| "#{name}: #{type_name}" end * ', ' ) + ")(implicit constellation: Constellation) = {\n" + # Define the constant storage for the identifying role values: id_names.map do |name| " val _#{name} = #{name}" end*"\n" + " val _constellation = constellation\n" + " assertEntity(new #{title_name} {\n" + id_names.map do |name| " val #{name} = _#{name}" end*"\n" + " val constellation = _constellation\n" + " })\n" + # Ends new block and assertEntity " }\n" + # Ends apply() " }\n" + # Ends object{} "\n" end |
#scala_objectification ⇒ Object
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
# File 'lib/activefacts/generators/traits/scala.rb', line 354 def scala_objectification # REVISIT: This disregards any supertypes and their identifiers # primary_supertype = o && (o.identifying_supertype || o.supertypes[0]) # secondary_supertypes = o.supertypes-[primary_supertype] pi = preferred_identifier id_roles = [] = pi.role_sequence.all_role_ref_in_order .each do |id_role_ref| id_roles << id_role_ref.role end id_names = id_role_names id_roles id_types = id_role_types id_roles " case class #{name.words.titlecase}(#{ id_names.zip(id_types).map {|(n, t)| "#{n}: #{t}" }*', ' }) extends FBMModel.ObjectifiedFact {\n" + " // REVISIT: Here, we should use fact_roles_dump(fact_type)\n" + absorbed_roles.map do |role| role.scala_role_definition end. compact*"\n" + " }" end |
#scala_objectification_metamodel ⇒ Object
381 382 383 384 |
# File 'lib/activefacts/generators/traits/scala.rb', line 381 def = preferred_identifier.role_sequence.all_role_ref_in_order.map{|rr| rr.role.object_type.name.words.camelcase }*', ' " val #{name.words.camelcase} = assertEntity(FBMModel.ObjectifiedType(FBMModel.DomainObjectTypeName(\"#{name.words.titlecase}\"), Nil, Seq(#{})))\n" end |
#scala_shared(o, supertypes, pi = nil) ⇒ Object
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
# File 'lib/activefacts/generators/traits/scala.rb', line 315 def scala_shared(o, supertypes, pi = nil) if supertypes primary_supertype = o && (o. || o.supertypes[0]) end title_name = o.name.words.titlecase id_roles, pis = *(o) id_names = id_role_names(o, id_roles) id_types = id_role_types(id_roles) identification = pi ? identified_by(o, pi) : nil # REVISIT: We don't want an object for abstract classes, # i.e. where subtypes have a disjoint mandatory constraint entity_object(title_name, id_names, id_types) entity_trait(o, title_name, primary_supertype, pis) entity_model(o, title_name) end |
#scala_trait(title_name, primary_supertype, pis) ⇒ Object
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/activefacts/generators/traits/scala.rb', line 273 def scala_trait(title_name, primary_supertype, pis) s = 'override ' unless supertypes.empty? " trait #{title_name} extends #{primary_supertype ? primary_supertype.name.words.titlecase : 'FBMModel.Entity'} {\n" + " #{s}val objectType = metaModel.#{name.words.camelcase}\n" + (fact_type ? " // REVISIT: Here, we should use fact_roles_dump(fact_type)\n\n" : '') + absorbed_roles.map do |role| role.scala_role_definition end. compact*"\n" + " #{s}val identifier: Seq[Seq[FBMModel.Identifier[_]]] = Seq(#{ pis.map do |pi| 'Seq(' + pi.role_sequence.all_role_ref_in_order.map do |id_role_ref| id_role_ref.role.object_type.name.words.camelcase end*', ' + ')' end*', ' })\n" + " }\n" + # Ends trait{} "\n" end |