Class: MongrelConsoleRunner

### Home Classes Methods

### In Files

- lib/mongrel_console/console.rb

### Parent

Object

### Methods

- ::new
- #get
- #restart
- #start
- #status
- #stop
- #tail

### Class/Module Index

Quicksearch

- Console
- MongrelConsoleRunner
- Object

No matching classes.

# MongrelConsoleRunner

### Public Class Methods

new() click to toggle source

    # File lib/mongrel_console/console.rb, line 17
    def initialize
      @port = 3000
      @env = "development"
    end

### Public Instance Methods

get(url="/") click to toggle source

    # File lib/mongrel_console/console.rb, line 69
    def get(url="/")
      Net::HTTP.get("localhost", url, @port)
    end

restart(port=@port, env=@env) click to toggle source

    # File lib/mongrel_console/console.rb, line 55
    def restart(port=@port, env=@env)
      stop
      start(port, env)
    end

start(port=@port, env=@env) click to toggle source

    # File lib/mongrel_console/console.rb, line 47
    def start(port=@port, env=@env)
      `mongrel_rails start #{port} #{env} -d`
    end

status() click to toggle source

    # File lib/mongrel_console/console.rb, line 60
    def status
      if File.exist? "log/mongrel.pid"
        pid = open("log/mongrel.pid") {|f| f.read.to_i }
        puts "Running on port #@port in env #@env with PID #{pid}"
      else
        puts "Mongrel not running."
      end
    end

stop() click to toggle source

    # File lib/mongrel_console/console.rb, line 51
    def stop
      `mongrel_rails stop`
    end

tail(file="log/#{@env}.log") click to toggle source

    # File lib/mongrel_console/console.rb, line 22
    def tail(file="log/#{@env}.log")
      STDERR.puts "Tailing #{file}.  CTRL-C to stop it."

      cursor = File.size(file)
      last_checked = Time.now
      tail_thread = Thread.new do
        File.open(file, 'r') do |f|
          loop do
            if f.mtime > last_checked
              f.seek cursor
              last_checked = f.mtime
              contents = f.read
              cursor += contents.length
              print contents
            end
            sleep 1
          end
        end
      end

      trap("INT") { tail_thread.kill }
      tail_thread.join
      nil
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.