Class: Roby::Planning::MethodModel
- Includes:
- MethodInheritance
- Defined in:
- lib/roby/planning/model.rb
Overview
The model of a planning method. This does not define an actual implementation of the method, only the model methods should abide to.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
The model name.
-
#options ⇒ Object
readonly
The model options, as a Hash.
Instance Method Summary collapse
- #==(model) ⇒ Object
-
#freeze ⇒ Object
Do not allow changing this model anymore.
-
#initialize(name, options = Hash.new) ⇒ MethodModel
constructor
A new instance of MethodModel.
-
#initialize_copy(from) ⇒ Object
:nodoc:.
-
#merge(new_options) ⇒ Object
call-seq: merge(new_options) => self.
- #overload(old_model) ⇒ Object
-
#returns ⇒ Object
The return type the method model defines.
-
#reuse? ⇒ Boolean
If the model allows reusing tasks already in the plan.
- #to_s ⇒ Object
Methods included from MethodInheritance
Constructor Details
#initialize(name, options = Hash.new) ⇒ MethodModel
Returns a new instance of MethodModel.
154 |
# File 'lib/roby/planning/model.rb', line 154 def initialize(name, = Hash.new); @name, @options = name, end |
Instance Attribute Details
#name ⇒ Object (readonly)
The model name
150 151 152 |
# File 'lib/roby/planning/model.rb', line 150 def name @name end |
#options ⇒ Object (readonly)
The model options, as a Hash
152 153 154 |
# File 'lib/roby/planning/model.rb', line 152 def @options end |
Instance Method Details
#==(model) ⇒ Object
155 156 157 |
# File 'lib/roby/planning/model.rb', line 155 def ==(model) name == model.name && == model. end |
#freeze ⇒ Object
Do not allow changing this model anymore
200 201 202 203 |
# File 'lib/roby/planning/model.rb', line 200 def freeze .freeze super end |
#initialize_copy(from) ⇒ Object
:nodoc:
205 206 207 208 |
# File 'lib/roby/planning/model.rb', line 205 def initialize_copy(from) # :nodoc: @name = from.name.dup @options = from..dup end |
#merge(new_options) ⇒ Object
call-seq:
merge() => self
Add new options in this model. Raises ArgumentError if the new options cannot be merged because they are incompatible with the current model definition
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/roby/planning/model.rb', line 165 def merge() (, [:returns, :reuse]) validate_option(, :returns, false) do |rettype| if [:returns] && [:returns] != rettype raise ArgumentError, "return type already specified for method #{name}" end [:returns] = rettype end validate_option(, :reuse, false) do |flag| if .has_key?(:reuse) && [:reuse] != flag raise ArgumentError, "the reuse flag is already set to #{[:reuse]} on #{name}" end [:reuse] = flag true end self end |
#overload(old_model) ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/roby/planning/model.rb', line 184 def overload(old_model) if old_returns = old_model.returns if returns && !(returns < old_returns) raise ArgumentError, "new return type #{returns} is not a subclass of the old one #{old_returns}" elsif !returns [:returns] = old_returns end end if .has_key?(:reuse) && old_model..has_key?(:reuse) && [:reuse] != old_model.reuse raise ArgumentError, "the reuse flag for #{name}h as already been set to #{[:reuse]} on our parent model" elsif !.has_key?(:reuse) && old_model..has_key?(:reuse) [:reuse] = old_model.reuse end end |
#returns ⇒ Object
The return type the method model defines
If this is nil, methods of this model may return a task array or a task aggregation
145 |
# File 'lib/roby/planning/model.rb', line 145 def returns; [:returns] end |
#reuse? ⇒ Boolean
If the model allows reusing tasks already in the plan
147 |
# File 'lib/roby/planning/model.rb', line 147 def reuse?; !.has_key?(:reuse) || [:reuse] end |
#to_s ⇒ Object
210 |
# File 'lib/roby/planning/model.rb', line 210 def to_s; "#{name}(#{})" end |