Class: Thin::Command

### Home Classes Methods

### In Files

- lib/thin/command.rb

### Parent

Object

### Methods

- ::new
- ::run
- #run
- #shellify

### Included Modules

- Thin::Logging

### Class/Module Index

Quicksearch

- Thin
- Thin::Backends
- Thin::Backends::Base
- Thin::Backends::SwiftiplyClient
- Thin::Backends::TcpServer
- Thin::Backends::UnixServer
- Thin::Command
- Thin::Connection
- Thin::Controllers
- Thin::Controllers::Cluster
- Thin::Controllers::Controller
- Thin::Controllers::Service
- Thin::Daemonizable
- Thin::Daemonizable::ClassMethods
- Thin::Headers
- Thin::InvalidOption
- Thin::InvalidRequest
- Thin::Logging
- Thin::Logging::SimpleFormatter
- Thin::OptionRequired
- Thin::PidFileExist
- Thin::PidFileNotFound
- Thin::PlatformNotSupported
- Thin::Request
- Thin::Response
- Thin::RestartTimeout
- Thin::Runner
- Thin::RunnerError
- Thin::Server
- Thin::Stats
- Thin::Stats::Adapter
- Thin::SwiftiplyConnection
- Thin::UnixConnection
- Rack
- Rack::Adapter
- Rack::Adapter::Rails
- Rack::Adapter::Rails::CGIWrapper
- Rack::Adapter::Rails::CgiApp
- Rack::AdapterNotFound
- Process

No matching classes.

# Thin::Command

Run a command through the `thin` command-line script.

### Attributes

script[RW]

Path to the `thin` script used to control the servers. Leave this to default to use the one in the path.

### Public Class Methods

new(name, options={}) click to toggle source

    # File lib/thin/command.rb, line 14
    def initialize(name, options={})
      @name    = name
      @options = options
    end

run(*args) click to toggle source

    # File lib/thin/command.rb, line 19
    def self.run(*args)
      new(*args).run
    end

### Public Instance Methods

run() click to toggle source

Send the command to the `thin` script

    # File lib/thin/command.rb, line 24
    def run
      shell_cmd = shellify
      trace shell_cmd
      trap('INT') {} # Ignore INT signal to pass CTRL+C to subprocess
      Open3.popen3(shell_cmd) do |stdin, stdout, stderr|
        log_info stdout.gets until stdout.eof?
        log_info stderr.gets until stderr.eof?
      end
    end

shellify() click to toggle source

Turn into a runnable shell command

    # File lib/thin/command.rb, line 35
    def shellify
      shellified_options = @options.inject([]) do |args, (name, value)|
        option_name = name.to_s.tr("_", "-")
        case value
        when NilClass,
             TrueClass then args << "--#{option_name}"
        when FalseClass
        when Array     then value.each { |v| args << "--#{option_name}=#{v.inspect}" }
        else                args << "--#{option_name}=#{value.inspect}"
        end
        args
      end

      raise ArgumentError, "Path to thin script can't be found, set Command.script" unless self.class.script

      "#{self.class.script} #{@name} #{shellified_options.compact.join(' ')}"
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.