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.



72
73
74
75
76
77
# File 'lib/docter/server.rb', line 72

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.



69
70
71
# File 'lib/docter/server.rb', line 69

def collection
  @collection
end

#optionsObject

Returns the value of attribute options.



70
71
72
# File 'lib/docter/server.rb', line 70

def options
  @options
end

#portObject

Returns the value of attribute port.



70
71
72
# File 'lib/docter/server.rb', line 70

def port
  @port
end

#templateObject (readonly)

Returns the value of attribute template.



69
70
71
# File 'lib/docter/server.rb', line 69

def template
  @template
end

Instance Method Details

#start(wait = true) ⇒ Object



79
80
81
82
83
84
85
86
87
88
# File 'lib/docter/server.rb', line 79

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



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

def stop()
  puts "Stopping Mongrel"
  @mongrel.stop if @mongrel
end