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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 995bd47ed001c93b1dcfbf4947ddbe77d8c8aea565891abc4a0de27e49d447e8
4
- data.tar.gz: a85c19cad725d5edad7f7913fb28125e62be72f365c4430f3f14b54e50f960a9
3
+ metadata.gz: 93976f3a0f28334f3540eb0936dc76af56a864dfeafde8464ad5fafd462492d4
4
+ data.tar.gz: d81cc6d4feff6c23d6f9e3414f716d3f2a47f6769cd7eaded9225034764c780a
5
5
  SHA512:
6
- metadata.gz: 7fc362b73a6a69d6136578ebbecd5b2a9b3fe0cc6f4679df3c50ad27143a8eb7374df39eea1bde298911150e919e76041f049e8ea211c59cd40b0a1f5abc6acd
7
- data.tar.gz: 5b9f7c1b5622693ee3e078d591a664b86ac86189e48744619fc2503d7080d8dc247548e858e23f9e75fc1c22ae1745501df8b763bb71c6d5fb7bef15a79e32c6
6
+ metadata.gz: 8ad898710f3bdfe34df0ed614540a77103c91fea9fe7f7c982a6d27642a351a40eea8bf174de3947ad7524d713c06956a0a16bf690dc28b8e8083ca0e41d0985
7
+ data.tar.gz: dc407ed63b81ec47a298b4dd78a4fe1b159d749d84a77a0f9f6995c0895a796362a609618bd8a31f328527d6ae554444812705cec4148c3be53f292c3ece75f3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- query_limiter (0.1.1)
4
+ query_limiter (0.1.2)
5
5
  activerecord (>= 5.0.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -22,8 +22,18 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
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
@@ -1,3 +1,3 @@
1
1
  module QueryLimiter
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: query_limiter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jitendra Kasaudhan