Multiple before_all blocks

27 views
Skip to first unread message

Ashley Moran

unread,
Nov 1, 2009, 9:56:51 AM11/1/09
to ram...@googlegroups.com
Hi

Am I right thinking that aspect blocks are not inherited, and you can
only have one of each type?

I wanted to do this:

class Controller < Ramaze::Controller
before_all do
# before all actions in the app
end
end

class FirstController < Controller
before_all do
# have the app stuff from Controller run, then...
# before all actions in this specific controller
end
end

but it does not appear possible. Is there a way to achieve cascading
before blocks?

Cheers
Ashley

--
http://www.patchspace.co.uk/
http://www.linkedin.com/in/ashleymoran
http://aviewfromafar.net/

hrnt

unread,
Nov 2, 2009, 9:30:36 AM11/2/09
to Ramaze


On 1 marras, 16:56, Ashley Moran <ashley.mo...@patchspace.co.uk>
wrote:
> Hi
>
> Am I right thinking that aspect blocks are not inherited, and you can  
> only have one of each type?

IIRC they are inherited, but derived classes override the before_all
in the superclass.

> I wanted to do this:
>
>    class Controller < Ramaze::Controller
>      before_all do
>        # before all actions in the app
>      end
>    end
>
>    class FirstController < Controller
>      before_all do
>        # have the app stuff from Controller run, then...
>        # before all actions in this specific controller
>      end
>    end
>
> but it does not appear possible.  Is there a way to achieve cascading  
> before blocks?

My implementation looks like this:

class Controller < Ramaze::Controller
before_all do
before_filter
end

def before_filter
# before all actions in the app
end
end

class FirstController < Controller
def before_filter
super

Ashley Moran

unread,
Nov 3, 2009, 4:37:42 AM11/3/09
to ram...@googlegroups.com

On Nov 02, 2009, at 2:30 pm, hrnt wrote:

> class Controller < Ramaze::Controller
> before_all do
> before_filter
> end
>
> def before_filter
> # before all actions in the app
> end
> end
>
> class FirstController < Controller
> def before_filter
> super
> # before all actions in this specific controller
> end
> end

Thanks hrnt

Is this documented? If not, I'll find a space to put it on the wiki
when Michael has signed me up.

I think it's less than ideal though. Two possible improvements spring
to mind:

* allow building up a list of blocks (like RSpec)
* warn when a block is being overridden from a parent class

WDYT? Worth filing a ticked for?

Reply all
Reply to author
Forward
0 new messages