Class: DRbQS::Setting::Execute

Inherits:
Base
  • Object
show all
Defined in:
lib/drbqs/setting/execute.rb

Constant Summary

Constants included from Misc

Misc::STRINGS_FOR_KEY

Instance Attribute Summary collapse

Attributes inherited from Base

#source

Instance Method Summary collapse

Methods inherited from Base

#clone, #string_for_shell, #value

Methods included from Misc

create_logger, create_uri, output_error, process_running_normally?, random_key, time_to_history_string, time_to_history_string2, uri_drbunix

Constructor Details

#initializeExecute

Returns a new instance of Execute.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/drbqs/setting/execute.rb', line 8

def initialize
  super(:all_keys_defined => true) do
    [:port, :server, :node].each do |key|
      register_key(key, :check => 1)
    end
    [:no_server, :no_node, :wait_server_finish, :information, :help].each do |key|
      register_key(key, :bool => true)
    end
    set_argument_condition(:<=, 1)
  end
  @server_argument = []
end

Instance Attribute Details

#server_argumentObject

Returns the value of attribute server_argument.



6
7
8
# File 'lib/drbqs/setting/execute.rb', line 6

def server_argument
  @server_argument
end

Instance Method Details

#exec(io = nil) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/drbqs/setting/execute.rb', line 52

def exec(io = nil)
  process_def = DRbQS::ProcessDefinition.new(@server, @node, @port, io)
  if @definition
    process_def.load(@definition)
    process_def.test_consistency
  end
  case @mode
  when :help
    io.puts process_def.usage if io
  when :information
    io.puts process_def.information_string if io
  else
    unless @no_server
      process_def.execute_server(@server_argument)
    end
    unless @no_node
      process_def.execute_node
    end
    if !@no_server && @wait_server_finish
      process_def.wait_server_finish
    end
  end
  true
end

#parse!Object

If there are invalid arguments, this method raises an error.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/drbqs/setting/execute.rb', line 23

def parse!
  super
  @port = get_first(:port) do |val|
    val.to_i
  end
  @no_server = set?(:no_server)
  @server = get_first(:server) do |val|
    val.intern
  end
  @no_node = set?(:no_node)
  @node = get_first(:node) do |val|
    val.split(',').map do |s|
      s.intern
    end
  end
  @definition = get_argument[0]
  if get_first(:help)
    @mode = :help
  elsif get_first(:information)
    @mode = :information
  else
    @mode = nil
  end
  @wait_server_finish = set?(:wait_server_finish)
  if @mode != :help && !@definition
    raise DRbQS::Setting::InvalidArgument, "Definition file must be specified."
  end
end