Class: Warbler::Traits::War::WebxmlOpenStruct

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/warbler/traits/war.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.


174
175
176
177
# File 'lib/warbler/traits/war.rb', line 174

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

Instance Method Details

#[](key) ⇒ Object


190
191
192
193
# File 'lib/warbler/traits/war.rb', line 190

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

#[]=(key, value) ⇒ Object


195
196
197
198
# File 'lib/warbler/traits/war.rb', line 195

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

#context_params(escape = true) ⇒ Object


200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/warbler/traits/war.rb', line 200

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

#servlet_context_listenerObject


179
180
181
182
183
184
185
186
187
188
# File 'lib/warbler/traits/war.rb', line 179

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


219
220
221
# File 'lib/warbler/traits/war.rb', line 219

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