I was discussing this on #merb with (I believe) Michael Klishin
yesterday about how to extend merb-core/dispatch/request.rb to support
arbitrary REQUEST_METHOD values. As it is right now it would require a
hideously unacceptable monkey patch to get it working.
The reason I want this is for a WebDAV plugin I've been playing at.
I'm sure there are other HTTP extensions out there that people also
might be interested in supporting.
How I've got it working at the moment (on 0.9.7):
In config/init.rb:
Merb::BootLoader.before_app_loads do
require 'lib/method_extensions'
Merb::Request.class_eval("include MethodExtensions")
# this looks retarded just as a test.
Merb::Request.add_methods(["lock", :proppatch], %w{unlock move},
"copy")
end
> cat lib/method_extensions.rb
module MethodExtensions
private
EXTENSIONS = [] unless defined? EXTENSIONS
public
def self.included(mod)
$stderr.puts "Evil monkey patching of merb-core"
mod.class_eval %{
def method
@method ||= begin
request_method = @env['REQUEST_METHOD'].downcase.to_sym
case request_method
when :get, :head, :put, :delete, :options
request_method
when :post
m = nil
self.class.http_method_overrides.each do |o|
m ||= o.call(self); break if m
end
m.downcase! if m
METHODS.include?(m) ? m.to_sym : :post
else
if supports_method?(request_method)
request_method
else
raise "Unknown REQUEST_METHOD:
[EMAIL PROTECTED]'REQUEST_METHOD']}"
end
end
end
end
def self.add_methods(*a)
[a].flatten.each do |method|
m_sym = method.to_s.downcase.to_sym
unless EXTENSIONS.include?(m_sym)
EXTENSIONS << m_sym
Merb::Request::METHODS << m_sym.to_s
Merb::Request.class_eval "def \#{m_sym}?() method == :
\#{m_sym} end"
end
end
end
}
end
def supports_method?(method)
EXTENSIONS.include?(method.to_s.downcase.to_sym)
end
end
On Nov 5, 2008, at 23:58 , Yehuda Katz wrote:
> Hey guys,
> We have one full day before Merb 1.0 final is released. In light of
> that,
> I'm making a call for remaining bugs that you consider urgently
> required
> before 1.0, and that can be fixed in the short time remaining.
>
> We'll probably release a few 1.0.x releases to continue to solidify
> the
> final release as bug reports come streaming in, but please limit your
> replies to this thread to urgent problems that can be fixed quickly.
>
> Thanks!
>
> --
> Yehuda Katz
> Developer | Engine Yard
> (ph) 718.877.1325
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"merb" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/merb?hl=en
-~----------~----~----~----~------~----~------~--~---