Class: Roby::PlanObject::InstanceHandler
- Defined in:
- lib/roby/plan_object.rb
Overview
Generic handling object for blocks that are stored on tasks (event handlers,poll, …)
The only configurable behaviour so far is the ability to specify what to do with the block when a task is replaced by another one. This is given as a :on_replace option, which can take only two values:
- drop
-
the handler is not copied
- copy
-
the handler is copied
The default is dependent on the receiving’s object state. For instance, abstract tasks will use a default of ‘copy’ while non-abstract one will use a default of ‘drop’.
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
The poll Proc object.
Class Method Summary collapse
- .filter_options(options, defaults) ⇒ Object
-
.handle_options(method, options, defaults) ⇒ Object
Helper method for validate_options and filter_options.
- .validate_options(options, defaults = Hash.new) ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#as_options ⇒ Object
Creates an option hash from this poll handler parameters that is valid for Task#poll.
-
#copy_on_replace? ⇒ Object
:method:copy_on_replace?.
-
#initialize(block, copy_on_replace) ⇒ InstanceHandler
constructor
A new instance of InstanceHandler.
Constructor Details
#initialize(block, copy_on_replace) ⇒ InstanceHandler
Returns a new instance of InstanceHandler.
97 98 99 100 |
# File 'lib/roby/plan_object.rb', line 97 def initialize(block, copy_on_replace) @block, @copy_on_replace = block, copy_on_replace end |
Instance Attribute Details
#block ⇒ Object (readonly)
The poll Proc object
58 59 60 |
# File 'lib/roby/plan_object.rb', line 58 def block @block end |
Class Method Details
.filter_options(options, defaults) ⇒ Object
93 94 95 |
# File 'lib/roby/plan_object.rb', line 93 def self.(, defaults) (:filter, , defaults) end |
.handle_options(method, options, defaults) ⇒ Object
Helper method for validate_options and filter_options
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/roby/plan_object.rb', line 75 def self.(method, , defaults) , other = Kernel.send("#{method}_options", , on_replace: (defaults[:on_replace] || :drop)) if ![:drop, :copy].include?([:on_replace]) raise ArgumentError, "wrong value for the :on_replace option. Expecting either :drop or :copy, got #{options[:on_replace]}" end if other return , other else return end end |
.validate_options(options, defaults = Hash.new) ⇒ Object
89 90 91 |
# File 'lib/roby/plan_object.rb', line 89 def self.(, defaults = Hash.new) (:validate, , defaults) end |
Instance Method Details
#==(other) ⇒ Object
112 113 114 115 |
# File 'lib/roby/plan_object.rb', line 112 def ==(other) @copy_on_replace == other.copy_on_replace? && @block == other.block end |
#as_options ⇒ Object
Creates an option hash from this poll handler parameters that is valid for Task#poll
104 105 106 107 108 109 110 |
# File 'lib/roby/plan_object.rb', line 104 def on_replace = if copy_on_replace? then :copy else :drop end { on_replace: on_replace } end |
#copy_on_replace? ⇒ Object
:method:copy_on_replace?
If true, this poll handler gets copied to the new task when the task holding the handler gets replaced
63 |
# File 'lib/roby/plan_object.rb', line 63 attr_predicate :copy_on_replace?, true |