module ActiveFacts::Generators::ScalaTraits::ValueType
Constants
- DataTypeMap
- LengthTypes
- ScaleTypes
Public Instance Methods
scala_definition(super_type_name, facets)
click to toggle source
# File lib/activefacts/generators/traits/scala.rb, line 201 def scala_definition(super_type_name, facets) vt_name = name.words.titlecase if d = DataTypeMap[super_type_name] super_type_name = d end super_type_title = super_type_name.words.titlecase super_type_camel = super_type_name.words.camelcase sometimes_optional = all_role.detect do |r| r.fact_type.all_role.size == 2 && (c = (r.fact_type.all_role.to_a-[r])[0]) and !c.is_mandatory end " case class #{vt_name}(value: #{super_type_title})(implicit val constellation: Constellation) extends FBMModel.ValueTypeValue[#{super_type_title}] {\n" + " val objectType = metaModel.#{vt_name.words.camelcase}\n" + # REVISIT: scala_type_params + # REVISIT: scala_value_restriction + # puts " restrict #{value_constraint.all_allowed_range_sorted.map{|ar| ar.to_s}*", "}\n" if value_constraint # REVISIT: scala_units + # puts " \# REVISIT: #{vt_name} is in units of #{unit.name}\n" if unit absorbed_roles.map do |role| role.scala_role_definition end. compact*"\n" + " }\n" + # Add implicit casts for the underlying data type: " implicit def #{super_type_camel}2#{vt_name}(value: #{super_type_title})(implicit constellation: Constellation): #{vt_name} = #{vt_name}(value)\n" + if sometimes_optional " implicit def #{super_type_camel}2#{vt_name}Option(value: #{super_type_title})(implicit constellation: Constellation): Option[#{vt_name}] = Some(#{vt_name}(value))\n" else "" end + "\n" end
scala_metamodel(super_type_name, facets)
click to toggle source
# File lib/activefacts/generators/traits/scala.rb, line 234 def scala_metamodel(super_type_name, facets) vt_name = name.words.titlecase super_type_title = super_type_name.words.titlecase # REVISIT: Remove facets that do not apply to the Scala data types params = [ LengthTypes.include?(super_type_name) ? facets[:length] : nil, ScaleTypes.include?(super_type_name) ? facets[:scale] : nil ].compact * ", " " val #{name.words.camelcase} = assertEntity(FBMModel.ValueType(FBMModel.DomainObjectTypeName(\"#{vt_name}\"), FBMModel.#{super_type_title}Type(#{params}), Nil))\n" end