Created
May 1, 2014 16:07
-
-
Save hlindberg/7fae2744d9a7266139fd to your computer and use it in GitHub Desktop.
Sample RGen model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'puppet' | |
require 'puppet/pops' | |
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 | |
include Puppet::Pops::Containment | |
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 | |
RimTypeEnum = RGen::MetamodelBuilder::DataTypes::Enum.new([:black, :silver]) | |
class Wheel < MyModelElement | |
has_attr 'rim', RimTypeEnum | |
has_attr 'rim_serial', String | |
end | |
ExtraEquipmentEnum = RGen::MetamodelBuilder::DataTypes::Enum.new([ | |
:gps, :stereo, :sun_roof, :metallic | |
]) | |
class Car < MyModelElement | |
has_attr 'reg_nbr', String, :defaultValueLiteral => 'UNREGISTERED' | |
has_many_attr 'extras', ExtraEquipmentEnum, :defaultValueLiteral => 'stereo' | |
contains_one 'engine', Engine, 'in_car' | |
contains_one_uni 'left_front', Wheel | |
contains_one_uni 'right_front', Wheel | |
contains_one_uni 'left_rear', Wheel | |
contains_one_uni 'right_rear', Wheel | |
end | |
class ServiceOrder < MyModelElement | |
has_one 'serviced_engine', Engine | |
end | |
class Garage < MyModelElement | |
contains_many_uni 'cars', Car | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment