yaqb 0.5.0 → 0.5.1

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: 52b5538714ede2b23c96104bb339eddac611bfdf8562c648bb29094840c409e7
4
- data.tar.gz: 78c09abab32cf2a75b1533cde2937d28dbea1bd86c9918fcd5b362bccf3eb29b
3
+ metadata.gz: 21e2ed937f7b14a5ab0dfcb64a183e1d4cc127ae194fc38482e1dec50b217a08
4
+ data.tar.gz: 924a57354b4b4e6934aaaf3455aa4fab0aec368c5f2fae1085c59a49344d3648
5
5
  SHA512:
6
- metadata.gz: b4a0aa3013b84a22f77b41e8b8d80a677cf96ded8e901635a8d683bc551d3c6b9a620a57e77e4c7df1b871b29046e4e2cb6b2dba2cb4ee82fc0fbf423f844d71
7
- data.tar.gz: 7e1a4174fae0e07b22d5b601f57652fd8e2b0564af1422b7c488904b8c78c078a2ac44e3558f2177ed647a250fc31a4200c90a54e73cbe2b71e8080e21e29d83
6
+ metadata.gz: 7bdfcdf4eede2b9df3e2520a64d825346c58b121e0dbd0495af39d4f9601232594090a770928bd956614e952fe2790e707c45675f9ce35daf3ba67d8961f9834
7
+ data.tar.gz: abca46cd2bfbd8e02bfbbfe5e8f31313e0511e29f70448cffb95c55b0720e79cc886a758e245ac643b5fde4d79539ac936b84a94eb1f86d61674c601c7592ed7
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- yaqb (0.5.0)
4
+ yaqb (0.5.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,14 +1,21 @@
1
1
  # Yaqb
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/yaqb`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ #### Yet Another Query Builder
4
+ Yaqb is query builder that will filter, sort and paginate your ActiveRecord collections.
4
5
 
5
- TODO: Delete this and the text above, and describe your gem
6
+ In addition to query building, presenters are used to manage what a consumer of your API can query.
6
7
 
7
8
  ## Installation
8
9
 
9
- Add this line to your application's Gemfile:
10
+ In your Gemfile
10
11
 
11
12
  ```ruby
13
+ # Choose your preferred pagination gem
14
+ gem 'kaminari' # or
15
+ gem 'will_paginate' # or
16
+ gem 'pagy'
17
+
18
+ # Then add
12
19
  gem 'yaqb'
13
20
  ```
14
21
 
@@ -20,9 +27,76 @@ Or install it yourself as:
20
27
 
21
28
  $ gem install yaqb
22
29
 
30
+ ## Configuration
31
+
32
+ By default, Yaqb will detect if you are using Kaminari, WillPaginate, or Pagy. If you want to change any of the configurable settings, you may do so:
33
+
34
+ ```ruby
35
+ Yaqb.configure do |config|
36
+ # If for whatever reason you are using multiple pagination gems, you can manually set which gem to use.
37
+ config.paginator = :kaminari # :will_paginate, :pagy
38
+ end
39
+ ```
40
+
23
41
  ## Usage
24
42
 
25
- TODO: Write usage instructions here
43
+ ### Controllers
44
+
45
+ In your controller, you will need to include the following the module: `Yaqb::Base`
46
+
47
+ ```ruby
48
+ class ApplicationController < ActionController::Base # or ActionController::API
49
+ include Yaqb::Base
50
+ end
51
+
52
+ # And then to use Yaqb
53
+
54
+ class BooksController < ApplicationController
55
+ def index
56
+ # #orchestrate expects a collection and a presenter.
57
+ # #orchestrate return a results object meaning you will have access to the following methods:
58
+ # #scope - This is your collection after being filtered, sorted and paginated
59
+ # #links - This returns a hash of links based on the paginated results.
60
+ result = orchestrate(Books.all, BookPresenter)
61
+
62
+ # Depending on your serializer you can render your data as so:
63
+ # BluePrinter gem by procore is being here:
64
+ render json: BookBlueprint.render(request.scope, root: :data, meta: { links: request.links })
65
+ end
66
+ end
67
+ ```
68
+
69
+ ### Presenters
70
+
71
+ Presenters will allow you to control what a consumer of your API can sort and filter by.
72
+
73
+ Your Presenter class will need to inherit from `Yaqb::Presenter`
74
+
75
+ ```ruby
76
+ class BookPresenter < Yaqb::Presenter
77
+ sort_by :id, :title, :created_at, :updated_at
78
+ filter_by :id, :title
79
+ end
80
+ ```
81
+
82
+ ### Handling Errors
83
+
84
+ By default Yaqb will rescue from `QueryBuilderError` and return that error to the consumer
85
+
86
+ Given the following API call:
87
+
88
+ `GET https://api.example.com/v1/books?per=a`
89
+
90
+ The following response will be returned
91
+
92
+ ```json
93
+ {
94
+ "error": {
95
+ "message": "Invalid pagination params. Only numbers are supported for \"page\" and \"per\"",
96
+ "invalid_params": "per=a"
97
+ }
98
+ }
99
+ ```
26
100
 
27
101
  ## Development
28
102
 
data/lib/yaqb/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Yaqb
4
- VERSION = '0.5.0'
4
+ VERSION = '0.5.1'
5
5
  end
data/yaqb.gemspec CHANGED
@@ -19,6 +19,8 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.required_ruby_version = '>= 2.3.0'
21
21
  spec.requirements << 'Kaminari'
22
+ spec.requirements << 'WillPaginate'
23
+ spec.requirements << 'Pagy'
22
24
 
23
25
  # Specify which files should be added to the gem when it is released.
24
26
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaqb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ronald Chacon
@@ -122,6 +122,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
122
  version: '0'
123
123
  requirements:
124
124
  - Kaminari
125
+ - WillPaginate
126
+ - Pagy
125
127
  rubygems_version: 3.0.3
126
128
  signing_key:
127
129
  specification_version: 4