On Jun 1, 2011, at 4:25 PM, Alan K. Stebbens wrote:

> I have planned about 15 models or so, and as part of my learning Hobo, it 
> seems necessary to define the 4 permission methods in each model.  Eg.
> 
> <code><pre>
>       class MyModel42 < ActiveRecord::Base
> 
>         def create_permitted?
>           acting_user.signed_up?
>         end
> 
>         def update_permitted?
>           acting_user.administrator? || owner_is?(acting_user)
>         end
> 
>         def destroy_permitted?
>           acting_user.administrator? || owner_is?(acting_user)
>         end
> 
>         def view_permitted?(field)
>           true
>         end
> </pre></code>
> 
> Since most of the models will use the same permissions, it should be simple 
> to have them inherit the "standard" permission methods.  Where are these 
> defined

There's not a "standard" place for them - that's sort of why they get generated 
into the model.

> Should I use a class hierarchy?   Eg:
> 
> <code><pre>
>       class StandardAppModel < ActiveRecord::Base

I wouldn't recommend this - it's using an extremely powerful language feature 
(inheritance) to DRY up a handful of lines of code. It'll also confuse Rails to 
no end.

> OR, should I use a module to define the permission methods, and include that 
> module into each model?
> 
> <code><pre>
>       module StandardPermissions
>               def create_permitted?
>                       …
>               end
>               def update_permitted?
>                       …
>               end
>               …
>       end
> 
>       class MyModel42 < ActiveRecord::Base
>               hobo_model
>               ...
>               include StandardPermissions
>       end
> </pre></code>

This is definitely the most "Rubyish" way to accomplish this. You also get the 
ability to call 'super' in your specific model permissions methods (AFAIK) so 
you can add things without having to repeat the standards.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" 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/hobousers?hl=en.

Reply via email to