Skip to content

Commit

Permalink
Remove %w(com org java javax) methods from WebxmlOpenStruct
Browse files Browse the repository at this point in the history
- they're likely to be common methods for web.xml config keys
- also add [] as a way to specify non-identifier keys
  • Loading branch information
nicksieger committed Aug 29, 2008
1 parent 3e40275 commit f1fc922
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 12 additions & 0 deletions lib/warbler/config.rb
Expand Up @@ -179,6 +179,8 @@ def auto_detect_rackup
end

class WebxmlOpenStruct < OpenStruct
%w(java com org javax).each {|name| undef_method name if Object.methods.include?(name) }

def initialize(key = 'webxml')
@key = key
@table = Hash.new {|h,k| h[k] = WebxmlOpenStruct.new(k) }
Expand All @@ -195,6 +197,16 @@ def servlet_context_listener
end
end

def [](key)
new_ostruct_member(key)
send(key)
end

def []=(key, value)
new_ostruct_member(key)
send("#{key}=", value)
end

def context_params
require 'cgi'
params = {}
Expand Down
6 changes: 5 additions & 1 deletion spec/warbler/config_spec.rb
Expand Up @@ -63,18 +63,22 @@
it "should generate context parameters from the webxml openstruct" do
config = Warbler::Config.new
config.webxml.a.b.c = "123"
config.webxml.com.example.config = "blah"
config.webxml.rails.env = 'staging'
config.webxml.jruby.min.runtimes = 2
config.webxml.jruby.max.runtimes = 4
config.webxml['org']['jruby']['rack'] = "rails"
params = config.webxml.context_params
params.should have_key('a.b.c')
params.should have_key('rails.env')
params.should have_key('jruby.min.runtimes')
params.should have_key('jruby.max.runtimes')
params['a.b.c'].should == "123"
params['com.example.config'].should == "blah"
params['rails.env'].should == "staging"
params['jruby.min.runtimes'].should == "2"
params['jruby.max.runtimes'].should == "4"
params['org.jruby.rack'].should == "rails"
end

it "should determine the context listener from the webxml.booter parameter" do
Expand All @@ -100,7 +104,7 @@

it "should HTML-escape all webxml keys and values" do
config = Warbler::Config.new
config.webxml.a.send("b&").c = "123<hi>456"
config.webxml.a["b&"].c = "123<hi>456"
config.webxml.context_params['a.b&amp;.c'].should == "123&lt;hi&gt;456"
end

Expand Down

0 comments on commit f1fc922

Please sign in to comment.