Class: Cute::TakTuk::Commands Private

Inherits:
Array
  • Object
show all
Defined in:
lib/cute/taktuk.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.

Validates the commands accepted by taktuk

Constant Summary collapse

TOKENS =

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

[
 'broadcast', 'downcast', 'exec', 'get', 'put', 'input', 'data',
 'file', 'pipe', 'close', 'line', 'target', 'kill', 'message',
 'network', 'state', 'cancel', 'renumber', 'update', 'option',
 'synchronize', 'taktuk_perl', 'quit', 'wait', 'reduce'
]

Instance Method Summary collapse

Instance Method Details

#<<(val) ⇒ 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.

Raises:

  • (ArgumentError)


343
344
345
346
# File 'lib/cute/taktuk.rb', line 343

def <<(val)
  raise ArgumentError.new("'Invalid TakTuk command '#{val}'") unless check(val)
  super(val)
end

#check(val) ⇒ 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.



348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# File 'lib/cute/taktuk.rb', line 348

def check(val)
  if val =~ /^-?\[.*-?\]$|^;$/
    true
  elsif val.nil? or val.empty?
    false
  else
    tmp = val.split(' ',2)
    return false unless valid?(tmp[0])
    if !tmp[1].nil? and !tmp[1].empty?
      check(tmp[1])
    else
      true
    end
  end
end

#to_cmdObject

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.



371
372
373
374
375
376
377
378
379
# File 'lib/cute/taktuk.rb', line 371

def to_cmd
  self.inject([]) do |ret,val|
    if val =~ /^\[(.*)\]$/
      ret + ['[',Regexp.last_match(1).strip,']']
    else
      ret + val.split(' ')
    end
  end
end

#valid?(value) ⇒ 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)


364
365
366
367
368
369
# File 'lib/cute/taktuk.rb', line 364

def valid?(value)
  TOKENS.each do |token|
    return true if token =~ /^#{Regexp.escape(value)}.*$/
  end
  return false
end