Class: Commands::Commands
Instance Attribute Summary collapse
-
#commands ⇒ Object
Returns the value of attribute commands.
-
#executor ⇒ Object
Returns the value of attribute executor.
-
#global_options ⇒ Object
Returns the value of attribute global_options.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#opts ⇒ Object
Returns the value of attribute opts.
Instance Method Summary collapse
- #<<(value) ⇒ Object
- #each(&block) ⇒ Object
- #enact(client) ⇒ Object
- #exec(cmd) ⇒ Object
- #get_field(field_symbol, default_value = nil) ⇒ Object
- #have(field_symbol) ⇒ Object
-
#initialize(logger, executor) ⇒ Commands
constructor
A new instance of Commands.
- #last ⇒ Object
- #parse_command(klass, name, description) ⇒ Object
- #parse_jobflows(args) ⇒ Object
- #parse_option(klass, name, description, parent_commands, *args) ⇒ Object
- #parse_options(parent_commands, options) ⇒ Object
- #size ⇒ Object
- #validate ⇒ Object
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
#commands ⇒ Object
Returns the value of attribute commands.
16 17 18 |
# File 'lib/commands.rb', line 16 def commands @commands end |
#executor ⇒ Object
Returns the value of attribute executor.
16 17 18 |
# File 'lib/commands.rb', line 16 def executor @executor end |
#global_options ⇒ Object
Returns the value of attribute global_options.
16 17 18 |
# File 'lib/commands.rb', line 16 def @global_options end |
#logger ⇒ Object
Returns the value of attribute logger.
16 17 18 |
# File 'lib/commands.rb', line 16 def logger @logger end |
#opts ⇒ Object
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 |
#last ⇒ Object
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 (parent_commands, ) for option in do klass, name, description = option[0..2] args = option[3..-1] self.parse_option(klass, name, description, parent_commands, *args) end end |
#size ⇒ Object
36 37 38 |
# File 'lib/commands.rb', line 36 def size @commands.size end |
#validate ⇒ Object
40 41 42 |
# File 'lib/commands.rb', line 40 def validate @commands.each { |x| x.validate } end |