rooble 0.4.4 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -2
- data/lib/rooble/version.rb +1 -1
- data/lib/rooble.rb +8 -1
- data/rooble.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed905e965fe2684fab586a1d5c429580d35a33ddebd1bfeee00e3af830b6aa4e
|
4
|
+
data.tar.gz: 91d759d813d3d6fd6184330e6b55185aa05ff5846b3de7706ca7649e362798c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93959a654f9d95d1b49b8f5f6f36927338c3610301cbce6153378e11459e5b58f70a51c0cf6fd2b35cf47d5925b31aec3cad28fb6c6ac23152d4902b9fdc4396
|
7
|
+
data.tar.gz: 5a4b04e1e2d6942a4c6db7407790d3a5df95916034a271c2d4a31ad3903781356f9896133fe95d21b89ab60d081202ec433c681ad00713d8dbf689d73d709fc5
|
data/README.md
CHANGED
@@ -94,14 +94,13 @@ Note that in the 3rd example we override the `max_records_per_page` so we will g
|
|
94
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.
|
95
95
|
|
96
96
|
``` ruby
|
97
|
-
Model.search(fields, search_term, options
|
97
|
+
Model.search(fields, search_term, **options)
|
98
98
|
```
|
99
99
|
|
100
100
|
**Arguments:**
|
101
101
|
|
102
102
|
- `fields` a string with a field name or string/symbol array with field names to make the query against
|
103
103
|
- `search_term` string with the term to search
|
104
|
-
- `order_by` how records will be ordered, defaults to the ID in Ascending order
|
105
104
|
- `options` a hash with a set of options. Please se below for more info.
|
106
105
|
|
107
106
|
`Model.search("name", "John")` will look for records which have **John** within the `name` attribute.
|
@@ -112,6 +111,8 @@ There is an extra options hash that you can pass to this method, the options are
|
|
112
111
|
* `include` an array/hash of symbols if you want to include other relations on the model. Same as with default rails include.
|
113
112
|
* `join` an array/hash of symbols if you want to join other relations on the model. Same as with default rails join.
|
114
113
|
* `id_fields: nil` an array of strings with id fields that should be considered on the search. This is important because we cannot do `LIKE` searches on integer fields so if you want to search both for text fields and in ID fields this should be set
|
114
|
+
* `partial_search` a boolean indicating if you want to do a pattern search. This is the same as just passing "%search_term%" as the search term.
|
115
|
+
* `order_by` a hash with a key/value on how records will be ordered, defaults to the ID in Ascending order (e.g. {id: :asc}).
|
115
116
|
|
116
117
|
**Examples**
|
117
118
|
|
data/lib/rooble/version.rb
CHANGED
data/lib/rooble.rb
CHANGED
@@ -54,7 +54,7 @@ module Rooble
|
|
54
54
|
# Searches through records for the given fields
|
55
55
|
#
|
56
56
|
|
57
|
-
def search(fields, search_term, options
|
57
|
+
def search(fields, search_term, **options)
|
58
58
|
if search_term.nil?
|
59
59
|
raise Rooble::Error.new "You need to give a search term"
|
60
60
|
end
|
@@ -65,6 +65,13 @@ module Rooble
|
|
65
65
|
|
66
66
|
raise Rooble::Error.new("You can only include or join relations, not both!") if ([:include, :join] - options.keys ).empty?
|
67
67
|
|
68
|
+
# Set default ordering
|
69
|
+
order_by = if options.has_key? :order_by
|
70
|
+
options[:order_by]
|
71
|
+
else
|
72
|
+
{id: :asc}
|
73
|
+
end
|
74
|
+
|
68
75
|
# check if we are doing pattern search
|
69
76
|
if options.has_key? :partial_search
|
70
77
|
search_term = "%#{search_term}%"
|
data/rooble.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
|
13
13
|
spec.summary = "Allows to paginate and search through ActiveRecord associations in rails."
|
14
14
|
spec.description = "Yet another unnecessary and selfishly-created pagination and search gem for rails. This gem will add methods to your ActiveRecord associations and classes so you can search and paginate."
|
15
|
-
spec.homepage = '
|
15
|
+
spec.homepage = 'https://bitbucket.org/gusrub/rooble'
|
16
16
|
spec.license = 'MIT'
|
17
17
|
spec.date = Date.today.to_s
|
18
18
|
spec.require_paths = ["lib"]
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gustavo Rubio
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -82,7 +82,7 @@ files:
|
|
82
82
|
- lib/rooble.rb
|
83
83
|
- lib/rooble/version.rb
|
84
84
|
- rooble.gemspec
|
85
|
-
homepage:
|
85
|
+
homepage: https://bitbucket.org/gusrub/rooble
|
86
86
|
licenses:
|
87
87
|
- MIT
|
88
88
|
metadata: {}
|