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.



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

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.



296
297
298
# File 'lib/roby/event_generator.rb', line 296

def block
  @block
end

Instance Method Details

#==(other) ⇒ Object



330
331
332
333
334
# File 'lib/roby/event_generator.rb', line 330

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



321
322
323
324
325
326
327
328
# File 'lib/roby/event_generator.rb', line 321

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

    { on_replace: mode, once: once? }
end

#call(*args) ⇒ Object



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

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)


311
312
313
# File 'lib/roby/event_generator.rb', line 311

def copy_on_replace?
    !!@copy_on_replace
end

#once?Boolean

True if this event handler should be called only once

Returns:

  • (Boolean)


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

def once?
    !!@once
end