Class: Rubord::CommandBase Abstract
- Inherits:
-
Object
- Object
- Rubord::CommandBase
- Defined in:
- lib/rubord/models/commands/base.rb
Overview
This class is abstract.
Base class for creating commands.
Class Attribute Summary collapse
-
.aliases_list ⇒ Object
readonly
Returns the value of attribute aliases_list.
-
.command_name ⇒ Object
readonly
Returns the value of attribute command_name.
-
.command_usage ⇒ Object
readonly
Returns the value of attribute command_usage.
-
.description_text ⇒ Object
readonly
Returns the value of attribute description_text.
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Class Method Summary collapse
- .aliases(*values) ⇒ Object
- .description(value) ⇒ Object
- .inherited(subclass) ⇒ Object
- .name(value) ⇒ Object
- .validate! ⇒ Object
Instance Method Summary collapse
- #aliases ⇒ Array<String>
- #description ⇒ String
-
#initialize(client) ⇒ CommandBase
constructor
A new instance of CommandBase.
- #inspect ⇒ Object
- #name ⇒ String
-
#run(_message, _args = []) ⇒ Object
abstract
Executes the command.
Constructor Details
#initialize(client) ⇒ CommandBase
Returns a new instance of CommandBase.
47 48 49 50 |
# File 'lib/rubord/models/commands/base.rb', line 47 def initialize(client) @client = client self.class.validate! end |
Class Attribute Details
.aliases_list ⇒ Object (readonly)
Returns the value of attribute aliases_list.
18 19 20 |
# File 'lib/rubord/models/commands/base.rb', line 18 def aliases_list @aliases_list end |
.command_name ⇒ Object (readonly)
Returns the value of attribute command_name.
18 19 20 |
# File 'lib/rubord/models/commands/base.rb', line 18 def command_name @command_name end |
.command_usage ⇒ Object (readonly)
Returns the value of attribute command_usage.
18 19 20 |
# File 'lib/rubord/models/commands/base.rb', line 18 def command_usage @command_usage end |
.description_text ⇒ Object (readonly)
Returns the value of attribute description_text.
18 19 20 |
# File 'lib/rubord/models/commands/base.rb', line 18 def description_text @description_text end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
45 46 47 |
# File 'lib/rubord/models/commands/base.rb', line 45 def client @client end |
Class Method Details
.aliases(*values) ⇒ Object
36 37 38 |
# File 'lib/rubord/models/commands/base.rb', line 36 def aliases(*values) @aliases_list.concat(values.map(&:to_s)) end |
.description(value) ⇒ Object
32 33 34 |
# File 'lib/rubord/models/commands/base.rb', line 32 def description(value) @description_text = value.to_s end |
.inherited(subclass) ⇒ Object
23 24 25 26 |
# File 'lib/rubord/models/commands/base.rb', line 23 def inherited(subclass) super subclass.instance_variable_set(:@aliases_list, []) end |
.name(value) ⇒ Object
28 29 30 |
# File 'lib/rubord/models/commands/base.rb', line 28 def name(value) @command_name = value.to_s end |
.validate! ⇒ Object
40 41 42 |
# File 'lib/rubord/models/commands/base.rb', line 40 def validate! raise ArgumentError, "Command #{self} is missing a name" unless @command_name end |
Instance Method Details
#aliases ⇒ Array<String>
63 64 65 |
# File 'lib/rubord/models/commands/base.rb', line 63 def aliases self.class.aliases_list end |
#description ⇒ String
58 59 60 |
# File 'lib/rubord/models/commands/base.rb', line 58 def description self.class.description_text end |
#inspect ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/rubord/models/commands/base.rb', line 76 def inspect attrs = [] attrs << "name=#{name.inspect}" if name attrs << "aliases=#{aliases.inspect}" unless aliases.empty? "#<#{self.class} #{attrs.join(' ')}>" end |
#name ⇒ String
53 54 55 |
# File 'lib/rubord/models/commands/base.rb', line 53 def name self.class.command_name end |
#run(_message, _args = []) ⇒ Object
This method is abstract.
Executes the command.
72 73 74 |
# File 'lib/rubord/models/commands/base.rb', line 72 def run(, _args = []) raise NotImplementedError, "#{self.class} must implement #run(message)" end |