elabs/pundit — pull request #149 by DylanFM (2014-05-19 06:01:59+00:00)
Title: Policy instance variable and writer

This changes the `@policy` instance variable to `@_policy`. `attr_writer :policy` has been replaced with a method writing to `@_policy` underneath, which keeps the `policy=` method available for injecting a policy and avoids any changes to the specs.

We work on a number of insurance apps, which usually have a Policy model. This PR comes about after trying to authorize a policy in a PoliciesController: `authorize @policy`. In this case, Pundit's `policy` method always returns the Policy instance in `@policy`, rather than its policy (amusingly named `PolicyPolicy`).

Rather than changing the instance variable in our app, I thought Pundit could follow the pattern it already uses for some instance variables such as `@_policy_scoped`.

Interested to hear your opinions on this change. This is my 1st time using Pundit, so if you can recommend a better way of going about this I'd like to hear it.