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
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
22 23 24 25 26 27 28 29 30 |
# File 'lib/uwa/server.rb', line 22 def <<(config) begin @widgets << @plugins[config[:name]].merge(config) rescue log(:warning, "Unable to register #{config[:name].inspect} at #{config[:path].inspect}") else log(:info, "Register #{config[:name].inspect} at #{config[:path].inspect}") end end |
#log(level, msg) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/uwa/server.rb', line 58 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
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/uwa/server.rb', line 32 def run m = nil begin $mongrel_debug_client = @debug m = Mongrel::HttpServer.new(@host, @port) if m.nil? m.register('/', UWA::Proxy.new) @widgets.each do || object = [:class].new object.script = [:script] object.css = [:css] [:params].to_a.each do |name, value| object.instance_variable_set(('@' + name.to_s).to_sym, value) end m.register([:path], object) end m.run.join rescue m.graceful_shutdown unless m.nil? log :error , $!. log :error, $!.backtrace log :error, "Retrying in 5 seconds..." sleep(5) retry end end |