Class: DJI::Command::Base

Inherits:
Thor
  • Object
show all
Defined in:
lib/dji/command/base.rb

Direct Known Subclasses

FedexCommand, TrackCommand, VersionCommand

Class Method Summary collapse

Class Method Details

.command_nameObject

Return command name without namespaces.

DJI::Command::TestCommand.command_name # => 'test'


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

def command_name
  @command_name ||= begin
    if command = name.to_s.split("::").last
      command.chomp!("Command")
      command.underscore
    end
  end
end

.inherited(base) ⇒ Object

:nodoc:



22
23
24
25
26
27
28
# File 'lib/dji/command/base.rb', line 22

def inherited(base) #:nodoc:
  super

  if base.name && base.name !~ /Base$/
    DJI::Command.subclasses << base
  end
end

.namespaceObject

Convenience method to get the namespace from the class name. It’s the same as Thor default except that the Command at the end of the class is removed.



14
15
16
17
18
19
20
# File 'lib/dji/command/base.rb', line 14

def namespace
  ActiveSupport::Inflector.underscore(
    ActiveSupport::Inflector.demodulize(
      name
    )
  ).chomp("_command").sub(/:command:/, ":")
end

.perform(command, args, config) ⇒ Object

:nodoc:



30
31
32
33
34
# File 'lib/dji/command/base.rb', line 30

def perform(command, args, config) # :nodoc:
  command = nil if Thor::HELP_MAPPINGS.include?(args.first)

  dispatch(command, args.dup, nil, config)
end