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 Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key = 'webxml') ⇒ WebxmlOpenStruct

Returns a new instance of WebxmlOpenStruct.


177
178
179
180
181
182
# File 'lib/warbler/traits/war.rb', line 177

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

  @servlet_filter_async = nil # true/false
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(mid, *args) ⇒ Object


194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/warbler/traits/war.rb', line 194

def method_missing(mid, *args)
  len = args.length
  if mname = mid[/.*(?==\z)/m]
    if len != 1
      raise ArgumentError, "wrong number of arguments (#{len} for 1)", caller(1)
    end
    modifiable[new_ostruct_member(mname)] = args[0]
  elsif len == 0
    @table[mid]
  else
    err = NoMethodError.new "undefined method `#{mid}' for #{self}", mid, args
    err.set_backtrace caller(1)
    raise err
  end
end

Instance Attribute Details

#servlet_filterObject


214
# File 'lib/warbler/traits/war.rb', line 214

def servlet_filter; @servlet_filter ||= 'org.jruby.rack.RackFilter' end

#servlet_filter_asyncObject

Returns the value of attribute servlet_filter_async


223
224
225
# File 'lib/warbler/traits/war.rb', line 223

def servlet_filter_async
  @servlet_filter_async
end

#servlet_filter_nameObject


217
# File 'lib/warbler/traits/war.rb', line 217

def servlet_filter_name; @servlet_filter_name ||= 'RackFilter' end

#servlet_filter_url_patternObject


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

def servlet_filter_url_pattern; @servlet_filter_url_pattern ||= '/*' end

Instance Method Details

#[](key) ⇒ Object


184
185
186
187
# File 'lib/warbler/traits/war.rb', line 184

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

#[]=(key, value) ⇒ Object


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

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

#respond_to_missing?(mid, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)

210
211
212
# File 'lib/warbler/traits/war.rb', line 210

def respond_to_missing?(mid, include_private = false)
  @table.key?(mid.to_s.chomp('=').to_sym) || super
end

#servlet_context_listenerObject


225
226
227
228
229
230
231
232
233
234
# File 'lib/warbler/traits/war.rb', line 225

def servlet_context_listener
  case booter
  when :rack
    'org.jruby.rack.RackServletContextListener'
  when :rails
    'org.jruby.rack.rails.RailsServletContextListener'
  else # default (due compatibility)
    'org.jruby.rack.rails.RailsServletContextListener'
  end
end

#servlet_context_listenersObject


236
237
238
# File 'lib/warbler/traits/war.rb', line 236

def servlet_context_listeners
  @servlet_context_listeners ||= [ servlet_context_listener ]
end

#servlet_context_params(escape = true) ⇒ Object Also known as: context_params


240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/warbler/traits/war.rb', line 240

def servlet_context_params(escape = true)
  require 'cgi'; params = {}
  @table.each do |k,v|
    case v
    when WebxmlOpenStruct
      v.context_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,_| ['ignored', *extra_ignored].include?(k.to_s) }
  params
end

#to_sObject


259
260
261
# File 'lib/warbler/traits/war.rb', line 259

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