sorty_sorter 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -12
- data/lib/sorty_sorter/version.rb +1 -1
- data/sorty_sorter.gemspec +2 -2
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61c6078ac8fca37df8b1d767178f82fc8d19fd6d
|
4
|
+
data.tar.gz: 936f24fd55994a7a50e646b042197c6976fe03ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c4deaa064946f5b7fa6894f0c820b62ec4c0cd8537173bb223963ab041ab8fd9b59d38a59ea42967f24b25557ce48e22156f46549aa92070db0813c8a0339b6
|
7
|
+
data.tar.gz: 237ad7f56cb9e317cb093338e2e4ee0bd6079875efd0b2a80b4c5655ad7bdd37272e891bd0a06d67ad7ae38f7b5e882ec78042e04c10bd3336d5efcfb2beb577
|
data/README.md
CHANGED
@@ -4,10 +4,7 @@
|
|
4
4
|
[![Code Climate](https://codeclimate.com/github/katpadi/sorty_sorter/badges/gpa.svg)](https://codeclimate.com/github/katpadi/sorty_sorter)
|
5
5
|
[![Test Coverage](https://codeclimate.com/github/katpadi/sorty_sorter/badges/coverage.svg)](https://codeclimate.com/github/katpadi/sorty_sorter/coverage)
|
6
6
|
|
7
|
-
This
|
8
|
-
|
9
|
-
When defining valid columns that are "sortable", you can choose to mask the attributes so the DB columns will not be announced to the world. In other words, you can choose to name your exposed attribute differently than your DB column name. See Usage #1 as reference.
|
10
|
-
|
7
|
+
This gem sorts AR collection when given a set of parameters that will be validated against the whitelisted attributes in the model.
|
11
8
|
|
12
9
|
## Installation
|
13
10
|
|
@@ -25,7 +22,7 @@ Or install it yourself as:
|
|
25
22
|
|
26
23
|
## Usage
|
27
24
|
|
28
|
-
1.
|
25
|
+
1. Define whitelist attributes to model:
|
29
26
|
|
30
27
|
```ruby
|
31
28
|
sort_with update_date: { updated_at: :desc },
|
@@ -33,9 +30,9 @@ Or install it yourself as:
|
|
33
30
|
```
|
34
31
|
|
35
32
|
In the example above, `update_date` is the exposed attribute and it represents the `updated_at` column in DB.
|
36
|
-
The
|
33
|
+
The whitelist hash represents the "valid" attributes that may be sorted.
|
37
34
|
|
38
|
-
2. Call
|
35
|
+
2. Call `sorty_sort` method:
|
39
36
|
|
40
37
|
```ruby
|
41
38
|
@collection.sorty_sort('name', 'asc')
|
@@ -45,16 +42,27 @@ There is also a bang method `sorty_sort!` that will raise an exception if you're
|
|
45
42
|
|
46
43
|
## Example
|
47
44
|
|
48
|
-
|
45
|
+
As mentioned, a definition of the whitelist hash should be done in the model.
|
49
46
|
|
50
|
-
```
|
51
|
-
|
47
|
+
```ruby
|
48
|
+
# app/models/drone.rb
|
49
|
+
|
50
|
+
class Drone < ActiveRecord::Base
|
51
|
+
# Define!
|
52
|
+
sort_with update_date: { updated_at: :desc },
|
53
|
+
points: { points: :asc },
|
54
|
+
title: { name: :asc }
|
55
|
+
end
|
52
56
|
```
|
53
57
|
|
54
|
-
|
58
|
+
The outer Hash keys (i.e. `update_date`) represent the "exposed" attributes whereas their corresponding values (`updated_at: :desc`) represent the DB column name as the key, and its default sort direction in case there is no argument passed as the value.
|
59
|
+
|
60
|
+
Say you want to sort the collection based on `name`, the parameter `title` should be passed because that is the "exposed" attribute.
|
61
|
+
|
62
|
+
Since the gem already mixed in a method `sorty_sort` to the ActiveRecord::Relation, you can do the following conveniently:
|
55
63
|
|
56
64
|
```ruby
|
57
|
-
Drone.
|
65
|
+
Drone.all.sorty_sort('title', 'asc')
|
58
66
|
```
|
59
67
|
|
60
68
|
## Contributing
|
data/lib/sorty_sorter/version.rb
CHANGED
data/sorty_sorter.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = SortySorter::VERSION
|
9
9
|
spec.authors = ["Kat Padilla"]
|
10
10
|
spec.email = ["hello@katpadi.ph"]
|
11
|
-
spec.summary = %q{
|
12
|
-
spec.description = %q{ This gem
|
11
|
+
spec.summary = %q{ This gem sorts AR collection when given a set of parameters that will be validated against the whitelisted attributes in the model. }
|
12
|
+
spec.description = %q{ This gem sorts AR collection when given a set of parameters that will be validated against the whitelisted attributes in the model. The gem mixed in a `sorty_sort` method in the ActiveRecord::Relation. }
|
13
13
|
spec.homepage = "https://github.com/katpadi/sorty_sorter"
|
14
14
|
spec.license = "MIT"
|
15
15
|
spec.required_ruby_version = '>= 1.9.3'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sorty_sorter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kat Padilla
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,9 +80,9 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '4.1'
|
83
|
-
description: " This gem
|
84
|
-
|
85
|
-
|
83
|
+
description: " This gem sorts AR collection when given a set of parameters that will
|
84
|
+
be validated against the whitelisted attributes in the model. The gem mixed in a
|
85
|
+
`sorty_sort` method in the ActiveRecord::Relation. "
|
86
86
|
email:
|
87
87
|
- hello@katpadi.ph
|
88
88
|
executables: []
|
@@ -130,8 +130,8 @@ rubyforge_project:
|
|
130
130
|
rubygems_version: 2.2.2
|
131
131
|
signing_key:
|
132
132
|
specification_version: 4
|
133
|
-
summary:
|
134
|
-
|
133
|
+
summary: This gem sorts AR collection when given a set of parameters that will be
|
134
|
+
validated against the whitelisted attributes in the model.
|
135
135
|
test_files:
|
136
136
|
- spec/params_spec.rb
|
137
137
|
- spec/sort_spec.rb
|