Class: AppleBot::Command

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*properties) ⇒ Command

Returns a new instance of Command.



5
6
7
8
9
# File 'lib/applebot/commands.rb', line 5

def initialize(*properties)
  options = properties.delete_at -1
  super(*properties)
  self.options = CommandOptionSet.new(options['required'], options['optional'])
end

Instance Attribute Details

#actionObject

Returns the value of attribute action

Returns:

  • (Object)

    the current value of action



4
5
6
# File 'lib/applebot/commands.rb', line 4

def action
  @action
end

#descriptionObject

Returns the value of attribute description

Returns:

  • (Object)

    the current value of description



4
5
6
# File 'lib/applebot/commands.rb', line 4

def description
  @description
end

#file_nameObject

Returns the value of attribute file_name

Returns:

  • (Object)

    the current value of file_name



4
5
6
# File 'lib/applebot/commands.rb', line 4

def file_name
  @file_name
end

#namespaceObject

Returns the value of attribute namespace

Returns:

  • (Object)

    the current value of namespace



4
5
6
# File 'lib/applebot/commands.rb', line 4

def namespace
  @namespace
end

#optionsObject

Returns the value of attribute options

Returns:

  • (Object)

    the current value of options



4
5
6
# File 'lib/applebot/commands.rb', line 4

def options
  @options
end

Class Method Details

.load_all!Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/applebot/commands.rb', line 11

def self.load_all!
  commands_file_path = File.join(AppleBot.phantom_scripts_path, '_commands.json')
  commands = JSON.parse(IO.read(commands_file_path))
  AppleBot.commands = commands.keys.map {|file|
    command_config = commands[file]
    args = [file] + [
      command_config['namespace'], command_config['action'],
      command_config['description'], command_config['options']
    ]
    Command.new(*args)
  }
end

Instance Method Details

#cli_commandObject



24
25
26
# File 'lib/applebot/commands.rb', line 24

def cli_command
  "#{namespace}:#{action}"
end

#ruby_methodObject



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

def ruby_method
  "#{action}_#{namespace}"
end