Module: Martin::ClassMethods
- Defined in:
- lib/martin/base.rb
Instance Method Summary collapse
-
#command(regexp, &block) ⇒ Object
Adds a command.
-
#configure(&block) ⇒ Object
Runs once, at the beginning of the application If there are multiple configure blocks, then each one will run in the order the were created.
-
#error(&block) ⇒ Object
When the user input matches non of the user’s commands then this method will run If there are multiple error blocks, then each one will run in the order the were created.
-
#run(args = ARGV.join(' ')) ⇒ Object
Runs the application on the given arguments.
Instance Method Details
#command(regexp, &block) ⇒ Object
Adds a command
44 45 46 |
# File 'lib/martin/base.rb', line 44 def command(regexp, &block) Commands << DSL::Command.new(regexp, block) end |
#configure(&block) ⇒ Object
Runs once, at the beginning of the application If there are multiple configure blocks, then each one will run in the order the were created.
37 38 39 |
# File 'lib/martin/base.rb', line 37 def configure(&block) Configures << DSL::Configure.new(block) end |
#error(&block) ⇒ Object
When the user input matches non of the user’s commands then this method will run If there are multiple error blocks, then each one will run in the order the were created.
54 55 56 |
# File 'lib/martin/base.rb', line 54 def error(&block) Errors << DSL::Error.new(block) end |
#run(args = ARGV.join(' ')) ⇒ Object
Runs the application on the given arguments
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/martin/base.rb', line 61 def run(args = ARGV.join(' ')) Configures.each do |configure| configure.block.call end Commands.each do |command| match = command.regexp.match(args) unless match.nil? command.block.call(*match.captures) else Errors.each do |error| error.block.call(args) end end end self end |