<commit_before># Shield

Shield is a policies clean API for using in Rails applications. The intention
is to have an easy way to use policies inside Rails applications with a clean
and well defined API.

The basic idea is to have some PORO to handle read operations without in case
those operations get a little bit complex.

The following resources brought some inspirations to the lib:

[Rails - the Missing Parts - Policies](http://eng.joingrouper.com/blog/2014/03/20/rails-the-missing-parts-policies)

[Doman Driven Rails - Yan Pritzker](http://www.windycityrails.org/videos/2014/#6)

[7 Patterns to Refactor Fat ActiveRecord Models](http://blog.codeclimate.com/blog/2012/10/17/7-ways-to-decompose-fat-activerecord-models/)

## Installation

Add this line to your application's Gemfile:

    gem 'shield'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install shield

## Usage

```ruby
# Simple case
module IsActiveUser
  def call(user)
    user.email_confirmed? && user.last_login_at > 14.days.ago    
  end
end

class Subscriber
  include Shield::Policies

  policies :is_active_user

  def subscribe(user)
    policies.apply!<commit_msg>Fix README to reflect proper API definition<commit_after># Shield

Shield is a policies clean API for using in Rails applications. The intention
is to have an easy way to use policies inside Rails applications with a clean
and well defined API.

The basic idea is to have some PORO to handle read operations without in case
those operations get a little bit complex.

The following resources brought some inspirations to the lib:

[Rails - the Missing Parts - Policies](http://eng.joingrouper.com/blog/2014/03/20/rails-the-missing-parts-policies)

[Doman Driven Rails - Yan Pritzker](http://www.windycityrails.org/videos/2014/#6)

[7 Patterns to Refactor Fat ActiveRecord Models](http://blog.codeclimate.com/blog/2012/10/17/7-ways-to-decompose-fat-activerecord-models/)

## Installation

Add this line to your application's Gemfile:

    gem 'shield'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install shield

## Usage

```ruby
# Simple case
class IsActiveUser
  def initialize(user)
    @user = user
  end

  def validate
    user.email_confirmed? && user.last_login_at > 14.days.ago
  end

  private

  attr_reader :user
end

class Subscriber
  include Shield

  def subscribe(user)
    policies.with(IsActiveUser.new(user)).apply
{'fraction_non_alphanumeric': 0.08106995884773663, 'fraction_numerical': 0.0205761316872428, 'mean_word_length': 3.9410569105691056, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1608219', 'n_tokens_mistral': 807, 'n_tokens_neox': 731, 'n_words': 263}