<commit_before>== HasScope

Has scope allows you to easily create controller filters based on your resources named scopes.
Imagine the following model called graduations:

  class Graduation < ActiveRecord::Base
    named_scope :featured, :conditions => { :featured => true }
    named_scope :by_degree, proc {|degree| { :conditions => { :degree => degree } } }
  end

You can use those named scopes as filters by declaring them on your controller:

  class GraduationsController < ApplicationController
    has_scope :featured, :type => :boolean
    has_scope :by_degree
  end

Now, if you want to apply them to an specific resource, you just need to call <tt>apply_scopes</tt>:

  class GraduationsController < ApplicationController
    has_scope :featured, :type => :boolean
    has_scope :by_degree
    has_scope :by_period, :using => [:started_at, :ended_at]

    def index
      @graduations = apply_scopes(Graduation).all
    end
  end

Then for each request:

  /graduations
  #=> acts like a normal request

  /graduations?featured=true
  #=> calls the named scope and bring featured graduations

  /graduations?featured=true&by_degree=phd
  #=> brings featured graduations with phd degree

  /graduations?params[by_period][started_at]=20100701&params[by_period][ended_at]=20101013
  #=> brings graduations in the given period

You can retrieve all the scopes applied in one action with <tt>current_scopes</tt> method.
In the last case, it would return: { :featured => true, :by_degree => "phd" }.

== Installation

HasScope is available as gem on Gemcutter, so just run the following:

    sudo gem install has_scope

If you want it as plugin, just do:

    script/plugin install git://github.com/plataformatec/has_scope.git

== Options

HasScope supports several options:

* <tt>:type</tt> - Checks the type of the parameter sent. If set to :boolean it just calls the named scope, without any argument. By default, it does not allow hashes or arrays to be given, except if type :hash or :array are set.

* <tt>:only</tt> - In which actions the scope is applied.

* <tt>:except</tt> - In which actions the scope is not applied.
<commit_msg>Fixes a little mistake in the README<commit_after>== HasScope

Has scope allows you to easily create controller filters based on your resources named scopes.
Imagine the following model called graduations:

  class Graduation < ActiveRecord::Base
    named_scope :featured, :conditions => { :featured => true }
    named_scope :by_degree, proc {|degree| { :conditions => { :degree => degree } } }
  end

You can use those named scopes as filters by declaring them on your controller:

  class GraduationsController < ApplicationController
    has_scope :featured, :type => :boolean
    has_scope :by_degree
  end

Now, if you want to apply them to an specific resource, you just need to call <tt>apply_scopes</tt>:

  class GraduationsController < ApplicationController
    has_scope :featured, :type => :boolean
    has_scope :by_degree
    has_scope :by_period, :using => [:started_at, :ended_at]

    def index
      @graduations = apply_scopes(Graduation).all
    end
  end

Then for each request:

  /graduations
  #=> acts like a normal request

  /graduations?featured=true
  #=> calls the named scope and bring featured graduations

  /graduations?params[by_period][started_at]=20100701&params[by_period][ended_at]=20101013
  #=> brings graduations in the given period

  /graduations?featured=true&by_degree=phd
  #=> brings featured graduations with phd degree

You can retrieve all the scopes applied in one action with <tt>current_scopes</tt> method.
In the last case, it would return: { :featured => true, :by_degree => "phd" }.

== Installation

HasScope is available as gem on Gemcutter, so just run the following:

    sudo gem install has_scope

If you want it as plugin, just do:

    script/plugin install git://github.com/plataformatec/has_scope.git

== Options

HasScope supports several options:

* <tt>:type</tt> - Checks the type of the parameter sent. If set to :boolean it just calls the named scope, without any argument. By default, it does not allow hashes or arrays to be given, except if type :hash or :array are set.

* <tt>:only</tt> - In which actions the scope is applied.

* <tt>:except</tt> - In which actions the scope is not applied.

{'fraction_non_alphanumeric': 0.08466342817487855, 'fraction_numerical': 0.007402266944251677, 'mean_word_length': 4.215922798552473, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4346698', 'n_tokens_mistral': 1287, 'n_tokens_neox': 1236, 'n_words': 502}