module Scoping
This is light-weight filtering helper class that will compose all given criteria (scopes). When using this class all filtering logic has to be stored in scopes instead of creating ad-hoc filtering objects.
Usage example:
composer = ScopeComposer.new(Challenge) composer.with_state = 'cancelled' composer.created_during_past = '1 week'
Or you can provide criteria as a second argument to new:
ScopeComposer.new(Challenge, with_state: 'cancelled', created_during_past: '1 week')
Which translates to:
Challenge.with_state(:cancelled).created_during_past('1 week')
If you want to call the scopes which do not take arguments, you can safely use them with one condition - the scope is ommited if the argument value given is not “1” or true.
For example:
ScopeComposer.new(Challenge, accepted: false)
Would not result in the scope `accepted` applied, but on the other hand following code would:
ScopeComposer.new(Challenge, accepted: "1")
Constants
- VERSION