Class: Roby::Interface::V2::Client::BatchContext Private

Inherits:
BasicObject
Defined in:
lib/roby/interface/v2/client.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Object used to gather commands in a batch

Defined Under Namespace

Classes: Return

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ BatchContext

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a new batch context

Parameters:

  • context (Object)

    the underlying interface object



447
448
449
450
# File 'lib/roby/interface/v2/client.rb', line 447

def initialize(context)
    @context = context
    @calls = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, **keywords) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Provides the action_name! syntax to start jobs



506
507
508
509
510
511
512
513
514
515
# File 'lib/roby/interface/v2/client.rb', line 506

def method_missing(m, *, **keywords) # rubocop:disable Style/MethodMissingSuper
    if (action_match = /(.*)!$/.match(m.to_s))
        return start_job(action_match[1], **keywords)
    end

    ::Kernel.raise ::NoMethodError.new(m),
                   "#{m} either does not exist, or is not "\
                   "supported in batch context (only "\
                   "starting and killing jobs is)"
end

Instance Method Details

#__callsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The set of operations that have been gathered so far



457
458
459
# File 'lib/roby/interface/v2/client.rb', line 457

def __calls
    @calls
end

#__processObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Process the batch and return the list of return values for all the calls in #__calls



519
520
521
# File 'lib/roby/interface/v2/client.rb', line 519

def __process
    @context.process_batch(self)
end

#__push(path, m, args, keywords = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Pushes an operation in the batch



462
463
464
# File 'lib/roby/interface/v2/client.rb', line 462

def __push(path, m, args, keywords = {})
    @calls << [path, m, args, keywords]
end

#drop_job(job_id) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Drop the given job within the batch

Note that as all batch operations, order does NOT matter



484
485
486
# File 'lib/roby/interface/v2/client.rb', line 484

def drop_job(job_id)
    __push([], :drop_job, [job_id])
end

#empty?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


452
453
454
# File 'lib/roby/interface/v2/client.rb', line 452

def empty?
    @calls.empty?
end

#kill_job(job_id) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Kill the given job within the batch

Note that as all batch operations, order does NOT matter



491
492
493
# File 'lib/roby/interface/v2/client.rb', line 491

def kill_job(job_id)
    __push([], :kill_job, [job_id])
end

#respond_to?(m, _include_private = false) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


495
496
497
498
499
500
501
# File 'lib/roby/interface/v2/client.rb', line 495

def respond_to?(m, _include_private = false)
    return true if BatchContext.method_defined?(m)

    return unless (action_match = /(.*)!$/.match(m.to_s))

    @context.has_action?(action_match[1])
end

#start_job(action_name, **arguments) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Start the given job within the batch

Note that as all batch operations, order does NOT matter

Raises:



471
472
473
474
475
476
477
478
479
# File 'lib/roby/interface/v2/client.rb', line 471

def start_job(action_name, **arguments)
    if @context.has_action?(action_name)
        __push([], :start_job, [action_name], arguments)
    else
        ::Kernel.raise ::Roby::Interface::V2::Client::NoSuchAction,
                       "there is no action called #{action_name} "\
                       "on #{@context}"
    end
end