Class: Commands::Commands

Inherits:
Object show all
Defined in:
lib/commands.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger, executor) ⇒ Commands

Returns a new instance of Commands.



18
19
20
21
22
23
24
25
26
# File 'lib/commands.rb', line 18

def initialize(logger, executor)
  @commands = []
  @opts = nil
  @global_options = {
    :jobflow => []
  }
  @logger = logger
  @executor = executor
end

Instance Attribute Details

#commandsObject

Returns the value of attribute commands.



16
17
18
# File 'lib/commands.rb', line 16

def commands
  @commands
end

#executorObject

Returns the value of attribute executor.



16
17
18
# File 'lib/commands.rb', line 16

def executor
  @executor
end

#global_optionsObject

Returns the value of attribute global_options.



16
17
18
# File 'lib/commands.rb', line 16

def global_options
  @global_options
end

#loggerObject

Returns the value of attribute logger.



16
17
18
# File 'lib/commands.rb', line 16

def logger
  @logger
end

#optsObject

Returns the value of attribute opts.



16
17
18
# File 'lib/commands.rb', line 16

def opts
  @opts
end

Instance Method Details

#<<(value) ⇒ Object



32
33
34
# File 'lib/commands.rb', line 32

def <<(value)
  @commands << value
end

#each(&block) ⇒ Object



48
49
50
# File 'lib/commands.rb', line 48

def each(&block)
  @commands.each(&block)
end

#enact(client) ⇒ Object



44
45
46
# File 'lib/commands.rb', line 44

def enact(client)
  @commands.each { |x| x.enact(client) }
end

#exec(cmd) ⇒ Object



93
94
95
# File 'lib/commands.rb', line 93

def exec(cmd)
  @executor.exec(cmd)
end

#get_field(field_symbol, default_value = nil) ⇒ Object



84
85
86
87
88
89
90
91
# File 'lib/commands.rb', line 84

def get_field(field_symbol, default_value=nil)
  value = @global_options[field_symbol]
  if ( value == nil ) then
    return default_value
  else
    return value
  end
end

#have(field_symbol) ⇒ Object



80
81
82
# File 'lib/commands.rb', line 80

def have(field_symbol)
  return @global_options[field_symbol] != nil
end

#lastObject



28
29
30
# File 'lib/commands.rb', line 28

def last
  @commands.last
end

#parse_command(klass, name, description) ⇒ Object



52
53
54
55
56
# File 'lib/commands.rb', line 52

def parse_command(klass, name, description)
  @opts.on(name, description) do |arg|
    self << klass.new(name, description, arg, self)
  end      
end

#parse_jobflows(args) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/commands.rb', line 72

def parse_jobflows(args)
  for arg in args do
    if arg =~ /^j-\w{5,20}$/  then
      @global_options[:jobflow] << arg
    end
  end
end

#parse_option(klass, name, description, parent_commands, *args) ⇒ Object



58
59
60
61
62
# File 'lib/commands.rb', line 58

def parse_option(klass, name, description, parent_commands, *args)
  @opts.on(name, description) do |arg|
    klass.new(name, description, arg, parent_commands, self, *args).attach(commands)
  end
end

#parse_options(parent_commands, options) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/commands.rb', line 64

def parse_options(parent_commands, options)
  for option in options do
    klass, name, description = option[0..2]
    args = option[3..-1]
    self.parse_option(klass, name, description, parent_commands, *args)
  end
end

#sizeObject



36
37
38
# File 'lib/commands.rb', line 36

def size
  @commands.size
end

#validateObject



40
41
42
# File 'lib/commands.rb', line 40

def validate
  @commands.each { |x| x.validate }
end