Class: ThinService::Runner
- Inherits:
-
Object
- Object
- ThinService::Runner
- Defined in:
- lib/thin-service.rb
Constant Summary collapse
- COMMANDS =
list of available commands
%w(install delete)
Instance Attribute Summary collapse
-
#command ⇒ Object
command to be runned.
-
#options ⇒ Object
parsed options.
Instance Method Summary collapse
-
#initialize(argv) ⇒ Runner
constructor
A new instance of Runner.
- #parse! ⇒ Object
- #parser ⇒ Object
- #run! ⇒ Object
Constructor Details
#initialize(argv) ⇒ Runner
Returns a new instance of Runner.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/thin-service.rb', line 15 def initialize(argv) @argv = argv @options = { :ruby_executables => %w(ruby.exe jruby.exe), :port => 80, :environment => 'production', :service_path => "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\", :service_key => 'Parameters', :directory => Dir.pwd } parse! end |
Instance Attribute Details
#command ⇒ Object
command to be runned
10 11 12 |
# File 'lib/thin-service.rb', line 10 def command @command end |
#options ⇒ Object
parsed options
13 14 15 |
# File 'lib/thin-service.rb', line 13 def @options end |
Instance Method Details
#parse! ⇒ Object
44 45 46 47 48 |
# File 'lib/thin-service.rb', line 44 def parse! parser.parse! @argv @command = @argv.shift @service = @argv.shift end |
#parser ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/thin-service.rb', line 30 def parser @parser ||= OptionParser.new do |opts| opts. = "Usage: thin-service #{COMMANDS.join('|')} [options]" opts.separator "" opts.separator "Options:" opts.on("-p", "--port PORT", "use PORT (default: #{@options[:port]})") { |port| @options[:port] = port } opts.on("-d", "--directory DIR", "Project directory (default: #{@options[:directory]})") { |directory| @options[:directory] = directory } opts.on("-e", "--environment ENVIRONMENT", "use ENVIRONMENT (default: #{@options[:environment]})") { |environment| @options[:environment] = environment } opts.on("-h", "--help", "Show this message") { puts opts; exit } end end |
#run! ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/thin-service.rb', line 50 def run! if ThinService::Runner::COMMANDS.include?(@command) && respond_to?(@command) send(@command) else raise ThinService::CommandNotSupported end end |