refined 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/README.md +18 -8
  2. data/lib/refined/scope_chain.rb +1 -0
  3. metadata +1 -1
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- `refined` is a technique for chaining scopes (or class methods as it were. see (http://elabs.se/blog/24-scopes-are-obsolete/ "Scopes Are Obsolete") to faciliate easy filtering of ActiveRecord collections.
1
+ `refined` is a technique for chaining scopes (or class methods as it were in rails (see http://elabs.se/blog/24-scopes-are-obsolete/ "Scopes Are Obsolete") to facilitate easy filtering of ActiveRecord collections.
2
2
 
3
3
  Installation
4
4
  ============
@@ -14,14 +14,24 @@ in a `Gemfile`:
14
14
  Example Use
15
15
  ===========
16
16
 
17
- ### A Simple Scenario
17
+ ### Simple collection scoping
18
+
19
+ This is not a super practical use but one could do:
20
+
21
+ Candidate.refined({status: "pending", skill: "advanced"})
22
+
23
+ However that's not much shorter than:
24
+
25
+ Candidate.where("status = ? OR skill = ?", "pending", "advanced")
26
+
27
+ ### A Simple View Filter
18
28
 
19
29
  Let's say you want to filter a list of candidates for hire by status and skill level. The code might look something like this.
20
30
 
21
31
  class Candidate < ActiveRecord::Base; end
22
32
 
23
33
  controller Candidates < ApplicationController
24
- expose(:candidates) { Candidate.refined(params[:filters] }
34
+ expose(:candidates) { Candidate.refined(params[:filters]) }
25
35
 
26
36
  def filter
27
37
  render :index
@@ -45,11 +55,11 @@ Let's say you want to filter a list of candidates for hire by status and skill l
45
55
  - ["Name", "Status", "Skill"].each do |header|
46
56
  %th header
47
57
  %tbody
48
- - candidates.each do |candidate|
49
- %tr
50
- %td= candidate.name
51
- %td= candidate.status
52
- %td= candidate.skill
58
+ - candidates.each do |candidate|
59
+ %tr
60
+ %td= candidate.name
61
+ %td= candidate.status
62
+ %td= candidate.skill
53
63
 
54
64
  The call to Candidate.refined(params[:filters]) will yield 2 class methods created on Candidate as such:
55
65
 
@@ -18,6 +18,7 @@ class Refined::ScopeChain
18
18
  end
19
19
 
20
20
  def chain!
21
+ return constant_name.scoped unless criteria.present?
21
22
  criteria.inject(constant_name) do |model, (method, arg)|
22
23
  construct(method, arg)
23
24
  model.send(method, arg)
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: refined
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Dave Ott