Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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