elabs/pundit — pull request #5 by deefour (2012-11-30 15:32:15+00:00)
Title: Adds support for `policy_class` model instance/class method for custom Policy

In a case where many model classes extend a single base class (think STI) and all Policy logic is common, it may be simpler to specify a Policy on the base class which extending classes will pickup/can override.

Given some

```ruby
class Blog < ActiveRecord::Base; end
```

and many other types of blogs

```ruby
class ArtificialBlog < Blog; end
class SportsBlog < Blog; end
# ...
```

Instead of recreating (likely) blank Policies for every model

```ruby
class BlogPolicy < Struct.new(:user, :blog)
# lots of logic
end

class ArtificialBlogPolicy < BlogPolicy; end
class SportsBlogPolicy < BlogPolicy; end
# ...
```

It may be simpler to just add the following to the `Blog` class

```ruby
class Blog < ActiveRecord::Base
def self.policy_class
BlogPolicy
end
end
```

In the event `SportsBlog` has some extra Policy logic it needs to implement, the method could be removed or overloaded.

```ruby
class SportsBlog < Blog
class << self
undef :policy_class
end
end
```

or

```ruby
class SportsBlog < Blog
def self.policy_class
SportsBlogPolicy
end
end
```