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 = {}) ⇒ 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.
101 102 103 104 |
# File 'lib/roby/plan_object.rb', line 101 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
60 61 62 |
# File 'lib/roby/plan_object.rb', line 60 def block @block end |
Class Method Details
.filter_options(options, defaults) ⇒ Object
97 98 99 |
# File 'lib/roby/plan_object.rb', line 97 def self.(, defaults) (:filter, , defaults) end |
.handle_options(method, options, defaults) ⇒ Object
Helper method for validate_options and filter_options
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/roby/plan_object.rb', line 78 def self.(method, , defaults) , other = Kernel.send("#{method}_options", , on_replace: defaults[:on_replace] || :drop) unless %i[drop copy].include?([:on_replace]) raise ArgumentError, "wrong value for the :on_replace option. Expecting either :drop or :copy, got #{[:on_replace]}" end if other [, other] else end end |
.validate_options(options, defaults = {}) ⇒ Object
93 94 95 |
# File 'lib/roby/plan_object.rb', line 93 def self.(, defaults = {}) (:validate, , defaults) end |
Instance Method Details
#==(other) ⇒ Object
117 118 119 120 |
# File 'lib/roby/plan_object.rb', line 117 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
108 109 110 111 112 113 114 115 |
# File 'lib/roby/plan_object.rb', line 108 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
66 |
# File 'lib/roby/plan_object.rb', line 66 attr_predicate :copy_on_replace?, true |