Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add array-based syntax for namespaced headless policies #216

Merged
1 commit merged into from
Mar 26, 2015

Conversation

RaZer
Copy link
Contributor

@RaZer RaZer commented Oct 11, 2014

Before to namespace headless policy we needed to use following syntax:

authorize :'project/dashboard'

Now we can use array to specify each constant separately so it looks cleaner

authorize [:project, :dashboard]

Before to namespace headless policy we needed to use following syntax:
  authorize :'project/dashboard'

Now we can use array to specify each constant separately so it looks cleaner
  authorize [:project, :dashboard]
@thomasklemm
Copy link
Collaborator

Looks good to me, I'm 👍 on this addition. It's the same as in Rails, where link_to [:project, :dashboard] stands for link_to project_dashboard_path. Thanks for including specs!

@johno
Copy link
Contributor

johno commented Jan 27, 2015

I'd love for this to be included at some point.

@@ -44,6 +44,8 @@ def find
object
elsif object.is_a?(Symbol)
object.to_s.classify
elsif object.is_a?(Array)
object.map(&:to_s).join('/').to_s.classify
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't this be put more simply as: object.join('/') since to_s is implicitly called or am I missing something?

2.2.0 :001 > [:a, :b].join('/')
 => "a/b" 
2.2.0 :002 > class Foo
2.2.0 :003?>   end
 => nil 
2.2.0 :004 > [Foo.new, :b].join('/')
 => "#<Foo:0x007f861a1686e8>/b" 

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Fixed.

@ghost ghost merged commit 9711b48 into varvet:master Mar 26, 2015
@jnicklas
Copy link
Collaborator

Merged! Thank you, nice idea :)

@jnicklas
Copy link
Collaborator

It actually just occurred to me. Can this be extended to allow truly namespaced policies? Something like policy(:admin, @post)? It would have to recurse through the array of course, but it might be doable!

@TangMonk TangMonk mentioned this pull request May 4, 2016
@emolayi
Copy link

emolayi commented May 19, 2017

Will namespacing be extended to the policy_scope method, @jnicklas?

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants