query_limiter 0.1.1 → 0.1.2
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +12 -2
- data/lib/query_limiter/limiter.rb +9 -1
- data/lib/query_limiter/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93976f3a0f28334f3540eb0936dc76af56a864dfeafde8464ad5fafd462492d4
|
4
|
+
data.tar.gz: d81cc6d4feff6c23d6f9e3414f716d3f2a47f6769cd7eaded9225034764c780a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ad898710f3bdfe34df0ed614540a77103c91fea9fe7f7c982a6d27642a351a40eea8bf174de3947ad7524d713c06956a0a16bf690dc28b8e8083ca0e41d0985
|
7
|
+
data.tar.gz: dc407ed63b81ec47a298b4dd78a4fe1b159d749d84a77a0f9f6995c0895a796362a609618bd8a31f328527d6ae554444812705cec4148c3be53f292c3ece75f3
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -22,8 +22,18 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
```ruby
|
26
|
+
class Product < ApplicationRecord
|
27
|
+
query_limiter
|
28
|
+
# max_query_limit 100 # limits results upto 100 items
|
29
|
+
end
|
30
|
+
|
31
|
+
rails c
|
32
|
+
products = Product.all
|
33
|
+
# By default maxium 5 items will be returned
|
34
|
+
# Underlying sql query used
|
35
|
+
# Product Load (1.0ms) SELECT "products".* FROM "products" LIMIT ? [["LIMIT", 5]]
|
36
|
+
```
|
27
37
|
## Development
|
28
38
|
|
29
39
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -3,12 +3,20 @@ require 'active_record'
|
|
3
3
|
ActiveSupport.on_load(:active_record) do
|
4
4
|
class ActiveRecord::Base
|
5
5
|
def self.query_limiter(options={})
|
6
|
+
class_attribute :max_limit
|
7
|
+
|
6
8
|
def self.limiter_scope
|
7
|
-
limit(5)
|
9
|
+
limit(self.max_limit || 5)
|
8
10
|
end
|
11
|
+
|
9
12
|
unless options[:without_default_scope]
|
10
13
|
default_scope { limiter_scope }
|
11
14
|
end
|
15
|
+
|
16
|
+
def self.max_query_limit(limit)
|
17
|
+
self.max_limit = limit
|
18
|
+
end
|
19
|
+
|
12
20
|
end
|
13
21
|
end
|
14
22
|
end
|