README.md in periscope-mongoid-1.1.0 vs README.md in periscope-mongoid-2.0.0

- old
+ new

@@ -1,6 +1,11 @@ -# Periscope [![Build Status](https://secure.travis-ci.org/laserlemon/periscope.png)](http://travis-ci.org/laserlemon/periscope) [![Dependency Status](https://gemnasium.com/laserlemon/periscope.png)](https://gemnasium.com/laserlemon/periscope) +# Periscope +[![Gem Version](https://badge.fury.io/rb/periscope.png)](http://badge.fury.io/rb/periscope) +[![Build Status](https://travis-ci.org/laserlemon/periscope.png?branch=master)](https://travis-ci.org/laserlemon/periscope) +[![Code Climate](https://codeclimate.com/github/laserlemon/periscope.png)](https://codeclimate.com/github/laserlemon/periscope) +[![Coverage Status](https://coveralls.io/repos/laserlemon/periscope/badge.png?branch=master)](https://coveralls.io/r/laserlemon/periscope) +[![Dependency Status](https://gemnasium.com/laserlemon/periscope.png)](https://gemnasium.com/laserlemon/periscope) Periscope provides a simple way to chain scopes on your models and to open those scopes up to your users. ## Installation @@ -49,12 +54,12 @@ Within your model you can use the `scope_accessible` method to specify which scopes you want Periscope to honor. ```ruby class User < ActiveRecord::Base - scope :gender, lambda{|g| where(gender: g) } - scope :makes, lambda{|s| where('salary >= ?', s) } + scope :gender, proc { |g| where(gender: g) } + scope :makes, proc { |s| where("salary >= ?", s) } scope_accessible :gender end ``` @@ -80,24 +85,24 @@ Parsers must respond to the `call` method, receiving the raw query parameter and returning an array of arguments to pass to the scope or class method. ```ruby class User < ActiveRecord::Base - scope :gender, lambda{|g| where(gender: g) } + scope :gender, proc { |g| where(gender: g) } - scope_accessible :gender, parser: lambda{|g| [g.downcase] } + scope_accessible :gender, parser: proc { |g| [g.downcase] } end ``` ### On/Off Scopes But not all scopes accept arguments. For scopes that you want to toggle on or off, you can set a `:boolean => true` option. Whenever the received parameter is truthy, the scope will be applied. Otherwise, it will be skipped. ```ruby class User < ActiveRecord::Base - scope :male, where(gender: 'male') - scope :female, where(gender: 'female') + scope :male, proc { where(gender: "male") } + scope :female, proc { where(gender: "female") } scope_accessible :male, :female, boolean: true end ``` @@ -109,30 +114,30 @@ class Project < ActiveRecord::Base scope_accessible :begin, method: :begins_after scope_accessible :end, method: :ends_before def self.begins_after(date) - where('begins_at >= ?', date) + where("begins_at >= ?", date) end def self.ends_before(date) - where('ends_at <= ?', date) + where("ends_at <= ?", date) end end ``` Alternatively, you can set `:prefix` and/or `:suffix` options, which will be applied to the query parameter name to determine the corresponding method name. ```ruby class Project < ActiveRecord::Base - scope_accessible :begin, :end, suffix: '_date' + scope_accessible :begin, :end, suffix: "_date" def self.begin_date(date) - where('begins_at >= ?', date) + where("begins_at >= ?", date) end def self.end_date(date) - where('ends_at <= ?', date) + where("ends_at <= ?", date) end end ``` ## This sucks.