basic-scopes 0.1.2 → 0.1.3
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.
- checksums.yaml +8 -8
- data/README.md +9 -4
- data/lib/basic-scopes/version.rb +1 -1
- data/lib/basic-scopes.rb +8 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
---
|
|
2
2
|
!binary "U0hBMQ==":
|
|
3
3
|
metadata.gz: !binary |-
|
|
4
|
-
|
|
4
|
+
NTU1YTUyMWQ4MjM1ZmJjYjUyNzk3MTg5ZGI2NWU5MjNjNTIzYzA4ZA==
|
|
5
5
|
data.tar.gz: !binary |-
|
|
6
|
-
|
|
6
|
+
NzlhYTk1NzFmMjUwYmE4Y2VjMTgxNzY2NDY0NDZjOTk2NzM3ZjNmMw==
|
|
7
7
|
SHA512:
|
|
8
8
|
metadata.gz: !binary |-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
OWFlYmRlMGMzNTE5NDRmMDk1YzZkM2MxYTdiMmYxNmRmOWIxYTcwOGUwNzk4
|
|
10
|
+
M2NjNmNlM2UxMjRlYTdlNTNiYTdjMjAzMWNiNjBkMWI2ZDg4NGY1ZGIyMTdm
|
|
11
|
+
NTMwNDMwNTEyN2I2ZmFiOWU0OTRhZmQ4ZDlkMTdhZTI3N2JlZjM=
|
|
12
12
|
data.tar.gz: !binary |-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
NGMxZGE3NmI2NzdjNDg3YmI4OTA5ODRlYzYzOTgzZTgzMTgyZjE1ZDdiZjcx
|
|
14
|
+
ODZiODcwM2Q3NzgzZjBlOGU3MDVlYzFlZTQ3MDhhNWQyODRkMzc0M2ZkNzQ3
|
|
15
|
+
MGZiZDljZGM3ZDEwZjI4YzVmMmYyNjU2YTU5ODZkNzlmMmYxYzY=
|
data/README.md
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
## basic-scopes
|
|
2
|
+
[](http://badge.fury.io/rb/basic-scopes)
|
|
2
3
|
[](https://travis-ci.org/vforge/basic-scopes)
|
|
3
4
|
[](https://gemnasium.com/vforge/basic-scopes)
|
|
4
5
|
[](https://codeclimate.com/github/vforge/basic-scopes)
|
|
6
|
+
[](https://bitdeli.com/free "Bitdeli Badge")
|
|
5
7
|
|
|
6
8
|
ActiveRecord basic scopes.
|
|
7
9
|
|
|
@@ -10,6 +12,8 @@ ActiveRecord basic scopes.
|
|
|
10
12
|
You can use basic-scopes just as normal ActiveRecord methods.
|
|
11
13
|
|
|
12
14
|
### Filtering
|
|
15
|
+
* `except_id(id)` - all records without matching `ID` field
|
|
16
|
+
* `filter_id(id)` - all recorth with matching `ID` field
|
|
13
17
|
* `except_ids(ids)` - all records without matching `ID` field
|
|
14
18
|
* `filter_ids(ids)` - all recorth with matching `ID` field
|
|
15
19
|
* `filter_updated_since(time)` - all records that have `UPDATED_AT` field greater than `time`
|
|
@@ -18,7 +22,8 @@ You can use basic-scopes just as normal ActiveRecord methods.
|
|
|
18
22
|
* `filter_created_till(time)` - all records that have `CREATED_AT` field lesser than `time`
|
|
19
23
|
|
|
20
24
|
|
|
21
|
-
**NOTE**: `ids` param
|
|
25
|
+
**NOTE**: `ids` param is an Array of `ID`s; `id` is single value
|
|
26
|
+
|
|
22
27
|
|
|
23
28
|
### Sorting / OrderBy
|
|
24
29
|
* `by_id` - order by `ID` descending
|
|
@@ -28,10 +33,10 @@ You can use basic-scopes just as normal ActiveRecord methods.
|
|
|
28
33
|
* `by_updated_at` - order by `UPDATED_AT` descending
|
|
29
34
|
* `by_updated_at_reversed` - order by `UPDATED_AT` ascending
|
|
30
35
|
|
|
31
|
-
##
|
|
36
|
+
## Examples
|
|
32
37
|
|
|
33
|
-
`
|
|
38
|
+
`Account.except_id(1)` - All Accounts except ID == 1.
|
|
39
|
+
`User.filter_updated_since(1.day).by_updated_at` - All Users updated in the last one day, ordered by time
|
|
34
40
|
|
|
35
41
|
|
|
36
|
-
[](https://bitdeli.com/free "Bitdeli Badge")
|
|
37
42
|
|
data/lib/basic-scopes/version.rb
CHANGED
data/lib/basic-scopes.rb
CHANGED
|
@@ -8,6 +8,14 @@ module BasicScopes
|
|
|
8
8
|
|
|
9
9
|
included do
|
|
10
10
|
class << self
|
|
11
|
+
def except_id(id)
|
|
12
|
+
self.where("#{self.table_name}.id <> ?", id)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def filter_id(id)
|
|
16
|
+
self.where("#{self.table_name}.id = ?", id)
|
|
17
|
+
end
|
|
18
|
+
|
|
11
19
|
def except_ids(ids)
|
|
12
20
|
self.where("#{self.table_name}.id NOT IN (?)", ids)
|
|
13
21
|
end
|