lib/roda/plugins/delegate.rb in roda-1.2.0 vs lib/roda/plugins/delegate.rb in roda-1.3.0

- old
+ new

@@ -1,10 +1,10 @@ class Roda module RodaPlugins # The delegate plugin allows you to easily setup instance methods in # the scope of the route block that call methods on the related - # request or response, which may offer a simpler API in some cases. + # request, response, or class which may offer a simpler API in some cases. # Roda doesn't automatically setup such delegate methods because # it pollutes the application's method namespace, but this plugin # allows the user to do so. # # Here's an example based on the README's initial example, using the @@ -41,9 +41,16 @@ # end # end # end module Delegate module ClassMethods + # Delegate the given methods to the class + def class_delegate(*meths) + meths.each do |meth| + define_method(meth){|*a, &block| self.class.send(meth, *a, &block)} + end + end + # Delegate the given methods to the request def request_delegate(*meths) meths.each do |meth| define_method(meth){|*a, &block| @_request.send(meth, *a, &block)} end