lib/trinidad/web_app.rb in trinidad-0.9.1 vs lib/trinidad/web_app.rb in trinidad-0.9.2
- old
+ new
@@ -1,19 +1,20 @@
module Trinidad
class WebApp
attr_reader :config, :app_config, :class_loader, :servlet
def self.create(config, app_config)
- app_config.has_key?(:rackup) ? RackupWebApp.new(config, app_config) : RailsWebApp.new(config, app_config)
+ rackup?(app_config) ? RackupWebApp.new(config, app_config) : RailsWebApp.new(config, app_config)
end
def initialize(config, app_config, servlet_class = 'org.jruby.rack.RackServlet', servlet_name = 'RackServlet')
@config = config
@app_config = app_config
@class_loader = org.jruby.util.JRubyClassLoader.new(JRuby.runtime.jruby_class_loader)
- @servlet = {:class => servlet_class, :name => servlet_name} unless rack_servlet_configured?
+
+ configure_rack_servlet(servlet_class, servlet_name) unless rack_servlet_configured?
end
def rack_listener
context_listener unless rack_listener_configured?
end
@@ -74,8 +75,21 @@
def web_context_param(param)
if web_xml =~ /<context-param><param-name>#{param}<\/param-name><param-value>(.+)<\/param-value>/
return $1
end
+ end
+
+ def configure_rack_servlet(servlet_class, servlet_name)
+ servlet_config = @config[:servlet] || @app_config[:servlet]
+ if servlet_config
+ servlet_class = servlet_config[:class]
+ servlet_name = servlet_config[:name]
+ end
+ @servlet = {:class => servlet_class, :name => servlet_name}
+ end
+
+ def self.rackup?(app_config)
+ app_config.has_key?(:rackup) || !Dir['WEB-INF/**/config.ru'].empty?
end
end
end