Class: Warbler::WebxmlOpenStruct

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/warbler/config.rb

Overview

Helper class for holding arbitrary config.webxml values for injecting into web.xml.

Instance Method Summary collapse

Constructor Details

#initialize(key = 'webxml') ⇒ WebxmlOpenStruct

Returns a new instance of WebxmlOpenStruct.



298
299
300
301
# File 'lib/warbler/config.rb', line 298

def initialize(key = 'webxml')
  @key = key
  @table = Hash.new {|h,k| h[k] = WebxmlOpenStruct.new(k) }
end

Instance Method Details

#[](key) ⇒ Object



314
315
316
317
# File 'lib/warbler/config.rb', line 314

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

#[]=(key, value) ⇒ Object



319
320
321
322
# File 'lib/warbler/config.rb', line 319

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

#context_paramsObject



324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# File 'lib/warbler/config.rb', line 324

def context_params
  require 'cgi'
  params = {}
  @table.each do |k,v|
    case v
    when WebxmlOpenStruct
      nested_params = v.context_params
      nested_params.each do |nk,nv|
        params["#{CGI::escapeHTML(k.to_s)}.#{nk}"] = nv
      end
    else
      params[CGI::escapeHTML(k.to_s)] = CGI::escapeHTML(v.to_s)
    end
  end
  params.delete_if {|k,v| ['ignored', *ignored].include?(k.to_s) }
  params
end

#servlet_context_listenerObject



303
304
305
306
307
308
309
310
311
312
# File 'lib/warbler/config.rb', line 303

def servlet_context_listener
  case self.booter
  when :rack
    "org.jruby.rack.RackServletContextListener"
  when :merb
    "org.jruby.rack.merb.MerbServletContextListener"
  else # :rails, default
    "org.jruby.rack.rails.RailsServletContextListener"
  end
end

#to_sObject



342
343
344
# File 'lib/warbler/config.rb', line 342

def to_s
  "No value for '#@key' found"
end