Class: Roby::EventGenerator::EventHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/roby/event_generator.rb

Overview

Class used to register event handler blocks along with their options

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block, copy_on_replace, once) ⇒ EventHandler

Returns a new instance of EventHandler.



287
288
289
# File 'lib/roby/event_generator.rb', line 287

def initialize(block, copy_on_replace, once)
    @block, @copy_on_replace, @once = block, copy_on_replace, once
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



285
286
287
# File 'lib/roby/event_generator.rb', line 285

def block
  @block
end

Instance Method Details

#==(other) ⇒ Object



314
315
316
317
318
# File 'lib/roby/event_generator.rb', line 314

def ==(other)
    @copy_on_replace == other.copy_on_replace? &&
        @once == other.once? &&
        block == other.block
end

#as_optionsObject

Generates an option hash valid for EventGenerator#on



306
307
308
309
310
311
312
# File 'lib/roby/event_generator.rb', line 306

def as_options
    mode = if copy_on_replace? then :copy
           else :drop
           end

    { on_replace: mode, once: once? }
end

#call(*args) ⇒ Object



291
292
293
# File 'lib/roby/event_generator.rb', line 291

def call(*args)
    block.call(*args)
end

#copy_on_replace?Boolean

True if this event handler should be moved to the new task in case of replacements

The default in Task#on is false for non-abstract tasks and true for abstract tasks.

Returns:

  • (Boolean)


300
# File 'lib/roby/event_generator.rb', line 300

def copy_on_replace?; !!@copy_on_replace end

#once?Boolean

True if this event handler should be called only once

Returns:

  • (Boolean)


303
# File 'lib/roby/event_generator.rb', line 303

def once?; !!@once end