Class: TestLink::Command::Base

Inherits:
Definition show all
Defined in:
lib/test_link/command/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Definition

argument, arguments, command_name

Class Method Details

.adapt_with(klass) ⇒ Object



58
59
60
# File 'lib/test_link/command/base.rb', line 58

def self.adapt_with klass
  TestLink::ApiLink.set_adapter_for self.command_name, klass
end

.remote_methodObject



54
55
56
# File 'lib/test_link/command/base.rb', line 54

def self.remote_method
  TestLink::ApiLink.remote_method self
end

Instance Method Details

#arguments_hashObject



31
32
33
34
35
36
37
# File 'lib/test_link/command/base.rb', line 31

def arguments_hash
  args = {}
  (Base.arguments.keys + self.class.arguments.keys).each do |name|
    args[name] = self.send(name)
  end
  args
end

#check_argumentsObject



46
47
48
49
50
51
52
# File 'lib/test_link/command/base.rb', line 46

def check_arguments
  errors = []
  self.class.arguments.select{ |name, argument| argument.mandatory? }.keys.each do |name|
    errors.push name if arguments_hash[name].nil?
  end
  errors
end

#execute(link) ⇒ Object



24
25
26
27
28
29
# File 'lib/test_link/command/base.rb', line 24

def execute link
  self.devKey ||= link.key
  errors = check_arguments
  raise ArgumentError.new "Missing mandatory argument(s) #{errors}" unless errors.empty?
  link.client.call 'tl.' + self.class.command_name, arguments_hash.reject { |key, value| value.nil? }
end

#reset_arguments_hash(hash) ⇒ Object



39
40
41
42
43
44
# File 'lib/test_link/command/base.rb', line 39

def reset_arguments_hash hash
  arguments_hash.keys.each do |name|
    assignment = (name.to_s + '=').to_sym
    send(assignment, hash[name])
  end
end