Skip to content

Instantly share code, notes, and snippets.

@hlindberg
Created April 29, 2014 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hlindberg/11406430 to your computer and use it in GitHub Desktop.
Save hlindberg/11406430 to your computer and use it in GitHub Desktop.
Small sample RGen model
require 'rgen/metamodel_builder'
module MyModel
# Let RGen now this module is a model
extend RGen::MetamodelBuilder::ModuleExtension
# An abstract class that makes it easier to check if a given
# object is an element of "MyModel"
#
class MyModelElement < RGen::MetamodelBuilder::MMBase
# We make this class abstract to make it impossible to create instances of it
abstract
end
class Engine < MyModelElement
abstract
end
FuelTypeEnum = RGen::MetamodelBuilder::DataTypes::Enum.new([:diesel, :petrol, :etanol])
class CombustionEngine < Engine
has_attr 'fuel', FuelTypeEnum
end
class ElectricalEngine < Engine
has_attr 'charge_time_h', Integer
end
ExtraEquipmentEnum = RGen::MetamodelBuilder::DataTypes::Enum.new([
:gps, :stereo, :sun_roof, :metallic
])
class Car < MyModelElement
has_attr 'test', ExtraEquipmentEnum
has_many_attr 'extras', ExtraEquipmentEnum
contains_one 'engine', Engine, 'in_car'
end
class ServiceOrder < MyModelElement
has_one 'serviced_engine', Engine
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment