public
Description: A very fast & simple Ruby web server
Homepage: http://code.macournoyer.com/thin/
Clone URL: git://github.com/macournoyer/thin.git
commit  f3417196f32db106f44feecf6bf2b77621c5b994
tree    4e66c97b8e3953434d2b4121a9dd642349bfc7ca
parent  fe618685efcb35f251865703a8028376008a5b10
thin / lib / thin / command.rb
100644 40 lines (35 sloc) 1.053 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
module Thin
  # Run a command though the +thin+ command-line script.
  class Command
    include Logging
    
    # Path to the +thin+ script used to control the servers.
    # Leave this to default to use the one in the path.
    attr_accessor :script
    
    def initialize(name, options={})
      @name = name
      @options = options
      @script = 'thin'
    end
    
    def self.run(*args)
      new(*args).run
    end
    
    # Send the command to the +thin+ script
    def run
      shell_cmd = shellify
      trace shell_cmd
      ouput = `#{shell_cmd}`.chomp
      log " " + ouput.gsub("\n", " \n") unless ouput.empty?
    end
    
    # Turn into a runnable shell command
    def shellify
      shellified_options = @options.inject([]) do |args, (name, value)|
        args << case value
        when NilClass
        when TrueClass then "--#{name}"
        else "--#{name.to_s.tr('_', '-')}=#{value.inspect}"
        end
      end
      "#{@script} #{@name} #{shellified_options.compact.join(' ')}"
    end
  end
end