Generic module included in all classes that are used as models.
The Roby plugin uses, as Roby does, Ruby classes as model objects. To ease code reading, the model-level functionality (i.e. singleton classes) are stored in separate modules whose name finishes with Model
For instance, the singleton methods of Component are defined on ComponentModel, Composition on CompositionModel and so on.
All models are defined in the context of a SystemModel instance. This is this instance
# File lib/orocos/roby/base.rb, line 125 def self.validate_model_name(prefix, user_name) name = user_name.dup PREFIX_SHORTCUTS[prefix].each do |str| name.gsub!(/^#{str}::/, '') end if name =~ /::/ raise ArgumentError, "model names cannot have sub-namespaces" end if !name.respond_to?(:to_str) raise ArgumentError, "expected a string as a model name, got #{name}" elsif !(name.camelcase(:upper) == name) raise ArgumentError, "#{name} is not a valid model name. Model names must start with an uppercase letter, and are usually written in UpperCamelCase" end name end
# File lib/orocos/roby/base.rb, line 105 def self.validate_service_model(model, system_model, expected_type = DataService) if !model.kind_of?(DataServiceModel) raise ArgumentError, "expected a data service, source or combus model, got #{model} of type #{model.class}" elsif !(model < expected_type) # Try harder. This is meant for DSL loading, as we define # data services for devices and so on if query_method = SystemModel::MODEL_QUERY_METHODS[expected_type] model = system_model.send(query_method, model.name) end if !model raise ArgumentError, "expected a submodel of #{expected_type.short_name} but got #{model} of type #{model.class}" end end model end
Returns a string suitable to reference self as a constant
This is for instance used by SystemModel to determine what name to use to export new models as constants:
# File lib/orocos/roby/base.rb, line 84 def constant_name name.gsub(/.*::/, '').camelcase(:upper) end
Creates a new class that is a submodel of this model
# File lib/orocos/roby/base.rb, line 99 def new_submodel klass = Class.new(self) klass.system_model = system_model klass end
# File lib/orocos/roby/base.rb, line 142 def short_name name.gsub('Orocos::RobyPlugin::', ''). gsub('DataServices', 'Srv'). gsub('Devices', 'Dev'). gsub('Compositions', 'Cmp') end
Returns a string suitable to reference an element of type
self.
This is for instance used by the composition if no explicit name is given:
add ElementModel
will have a default name of
ElementModel.snakename
# File lib/orocos/roby/base.rb, line 76 def snakename name.gsub(/.*::/, '').snakecase end