Class: Docter::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/docter/server.rb

Constant Summary collapse

PORT =
3000

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection, template, *args) ⇒ Server

Returns a new instance of Server.



92
93
94
95
96
97
# File 'lib/docter/server.rb', line 92

def initialize(collection, template, *args)
  @collection, @template = collection, template
  @options = Hash === args.last ? args.pop.clone : {}
  args.each { |arg| @options[arg.to_sym] = true }
  @port = @options[:port] || PORT
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



89
90
91
# File 'lib/docter/server.rb', line 89

def collection
  @collection
end

#optionsObject

Returns the value of attribute options.



90
91
92
# File 'lib/docter/server.rb', line 90

def options
  @options
end

#portObject

Returns the value of attribute port.



90
91
92
# File 'lib/docter/server.rb', line 90

def port
  @port
end

#templateObject (readonly)

Returns the value of attribute template.



89
90
91
# File 'lib/docter/server.rb', line 89

def template
  @template
end

Instance Method Details

#start(wait = true) ⇒ Object



99
100
101
102
103
104
105
106
107
108
# File 'lib/docter/server.rb', line 99

def start(wait = true)
  puts "Starting Mongrel on port #{port}"
  @mongrel = Mongrel::HttpServer.new('0.0.0.0', port, 4)
  @mongrel.register("/", MongrelHandler.new(collection, template, options))
  if wait
    @mongrel.run.join rescue nil
  else
    @mongrel.run
  end
end

#stopObject



110
111
112
113
# File 'lib/docter/server.rb', line 110

def stop
  puts 'Stopping Mongrel'
  @mongrel.stop if @mongrel
end