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.



301
302
303
304
# File 'lib/warbler/config.rb', line 301

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

Instance Method Details

#[](key) ⇒ Object



317
318
319
320
# File 'lib/warbler/config.rb', line 317

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

#[]=(key, value) ⇒ Object



322
323
324
325
# File 'lib/warbler/config.rb', line 322

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

#context_paramsObject



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

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



306
307
308
309
310
311
312
313
314
315
# File 'lib/warbler/config.rb', line 306

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



345
346
347
# File 'lib/warbler/config.rb', line 345

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