Class: Thin::Command
Class Thin::Command < Object
(in files lib/thin/command.rb )Run a command through the thin command-line script.
Includes
Methods
Public Class new(name, options={})
[ show source ]
# File lib/thin/command.rb, line 14
14: def initialize(name, options={})
15: @name = name
16: @options = options
17: end
Public Class run(*args)
[ show source ]
# File lib/thin/command.rb, line 19
19: def self.run(*args)
20: new(*args).run
21: end
Public Instance run()
Send the command to the thin script
[ show source ]
# File lib/thin/command.rb, line 24
24: def run
25: shell_cmd = shellify
26: trace shell_cmd
27: trap('INT') {} # Ignore INT signal to pass CTRL+C to subprocess
28: Open3.popen3(shell_cmd) do |stdin, stdout, stderr|
29: log stdout.gets until stdout.eof?
30: log stderr.gets until stderr.eof?
31: end
32: end
Public Instance shellify()
Turn into a runnable shell command
[ show source ]
# File lib/thin/command.rb, line 35
35: def shellify
36: shellified_options = @options.inject([]) do |args, (name, value)|
37: case value
38: when NilClass,
39: TrueClass then args << "--#{name}"
40: when FalseClass
41: when Array then value.each { |v| args << "--#{name}=#{v.inspect}" }
42: else args << "--#{name.to_s.tr('_', '-')}=#{value.inspect}"
43: end
44: args
45: end
46:
47: raise ArgumentError, "Path to thin script can't be found, set Command.script" unless self.class.script
48:
49: "#{self.class.script} #{@name} #{shellified_options.compact.join(' ')}"
50: end