rooble 0.4.3 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b8584c96b7c4cee5648017142702d8651e82950b6b3b80b98280adb754f82ef
4
- data.tar.gz: 87c83e64ec2c56dc5e2fd5b69e0b590edb25bfcc5ac2a2c4518688e6db839965
3
+ metadata.gz: ed905e965fe2684fab586a1d5c429580d35a33ddebd1bfeee00e3af830b6aa4e
4
+ data.tar.gz: 91d759d813d3d6fd6184330e6b55185aa05ff5846b3de7706ca7649e362798c9
5
5
  SHA512:
6
- metadata.gz: 3c1b12e7af88715295362eeb3604b1ef24f8e7094555c08a45f229faa7216d9495c774c07c7756de822b90c073311daf9ea629a20f3cda1466f6c2c67f253d88
7
- data.tar.gz: fc35839dc9590e582c23d98409c3747a83281c131d9f2502f2e0048eb7a6a3ac8bc1792bedb3b8eda5ba463ecc5a2029393b76bb66f20173749f80106d76528e
6
+ metadata.gz: 93959a654f9d95d1b49b8f5f6f36927338c3610301cbce6153378e11459e5b58f70a51c0cf6fd2b35cf47d5925b31aec3cad28fb6c6ac23152d4902b9fdc4396
7
+ data.tar.gz: 5a4b04e1e2d6942a4c6db7407790d3a5df95916034a271c2d4a31ad3903781356f9896133fe95d21b89ab60d081202ec433c681ad00713d8dbf689d73d709fc5
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,7 +94,7 @@ 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)
97
98
  ```
98
99
 
99
100
  **Arguments:**
@@ -110,6 +111,8 @@ There is an extra options hash that you can pass to this method, the options are
110
111
  * `include` an array/hash of symbols if you want to include other relations on the model. Same as with default rails include.
111
112
  * `join` an array/hash of symbols if you want to join other relations on the model. Same as with default rails join.
112
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}).
113
116
 
114
117
  **Examples**
115
118
 
@@ -1,3 +1,3 @@
1
1
  module Rooble
2
- VERSION = "0.4.3"
2
+ VERSION = "0.4.5"
3
3
  end
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={}, order_by: {id: :asc})
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 = 'http://github.com/gusrub/rooble'
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.3
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: 2022-10-13 00:00:00.000000000 Z
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: http://github.com/gusrub/rooble
85
+ homepage: https://bitbucket.org/gusrub/rooble
86
86
  licenses:
87
87
  - MIT
88
88
  metadata: {}