Module: Boson::Command::APIClassMethods
- Included in:
- Boson::Command
- Defined in:
- lib/boson/command.rb
Instance Method Summary collapse
-
#create(name, library) ⇒ Object
Creates a command given its name and a library.
-
#find(command, commands = Boson.commands) ⇒ Object
Finds a command, aliased or not.
-
#library_attributes(library) ⇒ Object
Attributes passed to commands from its library.
-
#new_attributes(name, library) ⇒ Object
Generates a command’s initial attributes when creating a command object.
Instance Method Details
#create(name, library) ⇒ Object
Creates a command given its name and a library.
7 8 9 |
# File 'lib/boson/command.rb', line 7 def create(name, library) new(new_attributes(name, library)) end |
#find(command, commands = Boson.commands) ⇒ Object
Finds a command, aliased or not. If found returns the command object, otherwise returns nil.
18 19 20 |
# File 'lib/boson/command.rb', line 18 def find(command, commands=Boson.commands) command && commands.find {|e| [e.name, e.alias].include?(command) } end |
#library_attributes(library) ⇒ Object
Attributes passed to commands from its library
12 13 14 |
# File 'lib/boson/command.rb', line 12 def library_attributes(library) {lib: library.name} end |
#new_attributes(name, library) ⇒ Object
Generates a command’s initial attributes when creating a command object
23 24 25 26 |
# File 'lib/boson/command.rb', line 23 def new_attributes(name, library) (library.commands_hash[name] || {}).merge(name: name). update(library_attributes(library)) end |