Class: Topicz::Application
- Inherits:
-
Object
- Object
- Topicz::Application
- Defined in:
- lib/topicz/application.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
Instance Method Summary collapse
-
#initialize(arguments = ARGV, factory = CommandFactory.new) ⇒ Application
constructor
A new instance of Application.
- #run ⇒ Object
Constructor Details
#initialize(arguments = ARGV, factory = CommandFactory.new) ⇒ Application
Returns a new instance of Application.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/topicz/application.rb', line 12 def initialize(arguments = ARGV, factory = CommandFactory.new) config_file = nil OptionParser.new do || . = 'Usage: topicz [options] <command> [options]' .program_name = 'topicz' .version = Topicz::VERSION .on('-c', '--config FILE', 'Uses FILE as the configuration file') do |file| config_file = file end .separator '' .separator 'Where <command> is one of: ' .separator '' .separator Topicz::COMMANDS.to_s end.order! arguments unless arguments.empty? command = arguments.shift if Topicz::COMMANDS.has_key? command @command = factory.create_command(command, config_file, arguments) end end end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
10 11 12 |
# File 'lib/topicz/application.rb', line 10 def command @command end |
Instance Method Details
#run ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/topicz/application.rb', line 35 def run if @command != nil @command.execute else raise 'Invalid command. Try topicz --help' end end |