Class: Commands::CommandOption

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, description, arg, parent_commands, commands, field_symbol = nil, pattern = nil) ⇒ CommandOption

Returns a new instance of CommandOption.



188
189
190
191
192
193
194
195
196
# File 'lib/commands.rb', line 188

def initialize(name, description, arg, parent_commands, commands, field_symbol=nil, pattern=nil)
  @name = name
  @description = description
  @arg = arg
  @parent_commands = parent_commands
  @commands = commands
  @field_symbol = field_symbol
  @pattern = pattern
end

Instance Attribute Details

#argObject

Returns the value of attribute arg.



186
187
188
# File 'lib/commands.rb', line 186

def arg
  @arg
end

#commandsObject

Returns the value of attribute commands.



186
187
188
# File 'lib/commands.rb', line 186

def commands
  @commands
end

#descriptionObject

Returns the value of attribute description.



186
187
188
# File 'lib/commands.rb', line 186

def description
  @description
end

#nameObject

Returns the value of attribute name.



186
187
188
# File 'lib/commands.rb', line 186

def name
  @name
end

#parent_commandsObject

Returns the value of attribute parent_commands.



186
187
188
# File 'lib/commands.rb', line 186

def parent_commands
  @parent_commands
end

Instance Method Details

#attach(commands) ⇒ Object

Raises:

  • (RuntimeError)


198
199
200
201
202
203
204
205
206
# File 'lib/commands.rb', line 198

def attach(commands)
  for command in commands.reverse do
    command_name = command.name.split(/\s+/).first
    if @parent_commands.include?(command_name) || @parent_commands.include?(command.class) then
      return command
    end
  end
  raise RuntimeError, "Expected argument #{name} to follow one of #{parent_commands.join(", ")}"
end