Class: UWA::Server
Instance Attribute Summary collapse
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#host ⇒ Object
Returns the value of attribute host.
-
#plugins ⇒ Object
Returns the value of attribute plugins.
-
#port ⇒ Object
Returns the value of attribute port.
-
#reload ⇒ Object
Returns the value of attribute reload.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(config) ⇒ Object
-
#initialize ⇒ Server
constructor
A new instance of Server.
- #log(level, msg) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize ⇒ Server
Returns a new instance of Server.
13 14 15 16 17 18 19 20 21 |
# File 'lib/uwa/server.rb', line 13 def initialize @host = '0.0.0.0' @port = 42080 @debug = true @reload = true @widgets = [] @mongrel = nil @plugins = [] end |
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
11 12 13 |
# File 'lib/uwa/server.rb', line 11 def debug @debug end |
#host ⇒ Object
Returns the value of attribute host.
11 12 13 |
# File 'lib/uwa/server.rb', line 11 def host @host end |
#plugins ⇒ Object
Returns the value of attribute plugins.
11 12 13 |
# File 'lib/uwa/server.rb', line 11 def plugins @plugins end |
#port ⇒ Object
Returns the value of attribute port.
11 12 13 |
# File 'lib/uwa/server.rb', line 11 def port @port end |
#reload ⇒ Object
Returns the value of attribute reload.
11 12 13 |
# File 'lib/uwa/server.rb', line 11 def reload @reload end |
Class Method Details
.method_missing(name, *args) ⇒ Object
7 8 9 |
# File 'lib/uwa/server.rb', line 7 def self.method_missing(name, *args) self.instance.send(name, *args) end |
Instance Method Details
#<<(config) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/uwa/server.rb', line 23 def <<(config) @plugins = UWA::Plugin.load if @plugins.empty? begin @widgets << @plugins[config[:name]].merge(config) rescue log(:warning, "Unable to configure #{config[:name].inspect} at #{config[:path].inspect}") else log(:info, "Configure #{config[:name].inspect} at #{config[:path].inspect}") end end |
#log(level, msg) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/uwa/server.rb', line 71 def log(level, msg) return unless @debug if msg.is_a? Array msg.each { |l| STDERR.puts " " + l } else STDERR.puts "#{Time.now}: #{level.to_s.upcase}: #{msg}" end STDERR.flush end |
#run ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/uwa/server.rb', line 35 def run begin $mongrel_debug_client = @debug @mongrel = Mongrel::HttpServer.new(@host, @port) if @mongrel.nil? @widgets.each do || unless @mongrel.classifier.uris.include?([:path]) object = [:class].new object.base = [:base] object.script = [:script] object.css = [:css] [:params].to_a.each do |name, value| object.instance_variable_set(('@' + name.to_s).to_sym, value) end @mongrel.register([:path], object) log(:info, "Register #{[:name].inspect} at #{[:path].inspect}") end end unless @mongrel.classifier.uris.include?('/proxy') @mongrel.register('/proxy', UWA::Proxy.new) log(:info, "Proxy at \"/proxy\"") end log(:info, "Ready to serve") @mongrel.run.join rescue Interrupt # Do nothing log(:info, "Shutdown") rescue Exception @mongrel.graceful_shutdown unless @mongrel.nil? log :error , $!. log :error, $!.backtrace log :error, "Retrying in 5 seconds..." sleep(5) retry end end |