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.
- data/README.md +18 -8
- data/lib/refined/scope_chain.rb +1 -0
- 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
|
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
|
-
###
|
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
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
|
data/lib/refined/scope_chain.rb
CHANGED