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

Unable to check for conditions if Subject instance does not exist #12

Open
oranges13 opened this issue Jul 20, 2016 · 0 comments
Open

Comments

@oranges13
Copy link

oranges13 commented Jul 20, 2016

I've found a very weird idiosyncrasy in the case that the Subject does not exist (checking for creation permissions is a good example of this).

Here's a rule pack:

def self.allowed(viewer, user)
    rules = []

    if viewer.is_admin?
        rules << :create_user
    end

    return rules unless user.instance_of?(User)

    # more rules here

    return rules
end

The above rule pack is IGNORED if used as written (declaration before the instance type check)

However, if I change the conditional statement to if viewer && viewer.is_admin? it works.

I have no idea WHY this occurs, but it is a very strange thing and it had me pulling my hair out trying to get this gem to work properly.

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

No branches or pull requests

1 participant