rooble 0.4.2 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/lib/rooble/version.rb +1 -1
- data/lib/rooble.rb +6 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e683f6845e705f291401d02c4fd35f75a2d95e6ec16136d08da48f2139df5e80
|
4
|
+
data.tar.gz: e5062b8a337dda95aea3b3e83e3505170af431eadf792aeda70625ae32245679
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8bebea75a21a281536f243755a37e62573b23c318ae53ffb52a80f336cc5cffbf2fd6baf916a28bd45aa6934745f9b5709fd6e5a8394bae553e10cd70252432
|
7
|
+
data.tar.gz: ec614c44c7d1f0e0afc14527400b2e57d84a7fd76b498f0c401b27cce5745421e1fbad8377a430c28ab88c11d66421b85d4af25d176f9a866ca8ef3ae14dc7d6
|
data/README.md
CHANGED
@@ -61,13 +61,14 @@ We can override the `max_records_per_page` as well on the first argument which i
|
|
61
61
|
```
|
62
62
|
|
63
63
|
``` ruby
|
64
|
-
Model.paginate(page=1, max_records_per_page=nil)
|
64
|
+
Model.paginate(page=1, max_records_per_page=nil, order_by: {id: :asc})
|
65
65
|
```
|
66
66
|
|
67
67
|
**Arguments:**
|
68
68
|
|
69
69
|
- `page` the page to pull records from
|
70
70
|
- `max_records_per_page` how many records to generate per page, this overrides the initializer option
|
71
|
+
- `order_by` how records will be ordered, defaults to the ID in Ascending order
|
71
72
|
|
72
73
|
`Model.paginate` will pull records for the first page. The first argument is the page number and you can also override the `max_records_per_page` config option on the second argument so that you paginate a specific page with a different amount of max records, for instance:
|
73
74
|
|
@@ -93,13 +94,14 @@ Note that in the 3rd example we override the `max_records_per_page` so we will g
|
|
93
94
|
The search method will lookup for keyword matches within columns or records that match a given id, this means that you can essentially use it only to search in text fields or in the primary key. So for instance if you try to search against numeric columns it won't work but for that type of specific search you are better off using ActiveRecord directly. The rational behind this is that most application _open_ searches will lookup for id's, names or codes, rarely against numeric values.
|
94
95
|
|
95
96
|
``` ruby
|
96
|
-
Model.search(fields, search_term, options={})
|
97
|
+
Model.search(fields, search_term, options={}, order_by: {id: :asc})
|
97
98
|
```
|
98
99
|
|
99
100
|
**Arguments:**
|
100
101
|
|
101
102
|
- `fields` a string with a field name or string/symbol array with field names to make the query against
|
102
103
|
- `search_term` string with the term to search
|
104
|
+
- `order_by` how records will be ordered, defaults to the ID in Ascending order
|
103
105
|
- `options` a hash with a set of options. Please se below for more info.
|
104
106
|
|
105
107
|
`Model.search("name", "John")` will look for records which have **John** within the `name` attribute.
|
data/lib/rooble/version.rb
CHANGED
data/lib/rooble.rb
CHANGED
@@ -36,7 +36,7 @@ module Rooble
|
|
36
36
|
# Returns a set of paginated records given a page.
|
37
37
|
#
|
38
38
|
|
39
|
-
def paginate(page=1, max_records_per_page=nil)
|
39
|
+
def paginate(page=1, max_records_per_page=nil, order_by: {id: :asc})
|
40
40
|
page ||= 1
|
41
41
|
|
42
42
|
if page.to_i < 0
|
@@ -45,14 +45,16 @@ module Rooble
|
|
45
45
|
|
46
46
|
max_records_per_page ||= Rooble::configuration.max_records_per_page
|
47
47
|
current_offset = ((page.to_i*max_records_per_page))-max_records_per_page
|
48
|
-
records = self.limit(max_records_per_page)
|
48
|
+
records = self.limit(max_records_per_page)
|
49
|
+
.offset(current_offset)
|
50
|
+
.order(**order_by)
|
49
51
|
end
|
50
52
|
|
51
53
|
##
|
52
54
|
# Searches through records for the given fields
|
53
55
|
#
|
54
56
|
|
55
|
-
def search(fields, search_term, options={})
|
57
|
+
def search(fields, search_term, options={}, order_by: {id: :asc})
|
56
58
|
if search_term.nil?
|
57
59
|
raise Rooble::Error.new "You need to give a search term"
|
58
60
|
end
|
@@ -130,6 +132,7 @@ module Rooble
|
|
130
132
|
end
|
131
133
|
|
132
134
|
records = model.where(query.join(' OR '), *search_values)
|
135
|
+
.order(**order_by)
|
133
136
|
end
|
134
137
|
|
135
138
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rooble
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gustavo Rubio
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|