api_helper 0.1.2 → 0.1.3
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/README.md +6 -6
- data/lib/api_helper/filterable.rb +4 -4
- data/lib/api_helper/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b3c62a17cbcc5826c91653645c8c2d74ad5816c
|
4
|
+
data.tar.gz: 756983a3ff914855c209e919ed2005d44426f8f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bfbe426ec912739f3126e9d686522fae232ff637128d6516482fbc1490d1f35e893f7a772deccb2c26fc50f6becee0144dfd49af24238640e5df7e55b25b811
|
7
|
+
data.tar.gz: 8ea1bb0c2fa17ba9b5280e45f3c6789da3ad6ea540739b635543c14ef8c94ca22beee35441fd1f6f7477edb6ae6d5fe8397f35a7ac6f254d6f5c94fcf480f8d2
|
data/README.md
CHANGED
@@ -49,9 +49,9 @@ Include each helper concern you need in an `ActionController::Base`:
|
|
49
49
|
|
50
50
|
```ruby
|
51
51
|
PostsController < ApplicationController
|
52
|
-
include
|
53
|
-
include
|
54
|
-
include
|
52
|
+
include APIHelper::Filterable
|
53
|
+
include APIHelper::Paginatable
|
54
|
+
include APIHelper::Sortable
|
55
55
|
|
56
56
|
# ...
|
57
57
|
|
@@ -66,9 +66,9 @@ Set the helpers you need in an `Grape::API`:
|
|
66
66
|
|
67
67
|
```ruby
|
68
68
|
class PostsAPI < Grape::API
|
69
|
-
helpers
|
70
|
-
helpers
|
71
|
-
helpers
|
69
|
+
helpers APIHelper::Filterable
|
70
|
+
helpers APIHelper::Paginatable
|
71
|
+
helpers APIHelper::Sortable
|
72
72
|
|
73
73
|
# ...
|
74
74
|
|
@@ -40,7 +40,7 @@ require 'active_support/core_ext/object/blank'
|
|
40
40
|
# Include this +Concern+ in your Action Controller:
|
41
41
|
#
|
42
42
|
# SamplesController < ApplicationController
|
43
|
-
# include
|
43
|
+
# include APIHelper::Filterable
|
44
44
|
# end
|
45
45
|
#
|
46
46
|
# or in your Grape API class:
|
@@ -71,7 +71,7 @@ module APIHelper::Filterable
|
|
71
71
|
# +Array+ of +Symbol+s fields that are allowed to be filtered, defaults
|
72
72
|
# to all
|
73
73
|
#
|
74
|
-
def filter(resource, filterable_fields: [])
|
74
|
+
def filter(resource, filterable_fields: [], ignore_unknown_fields: true)
|
75
75
|
# parse the request parameter
|
76
76
|
if params[:filter].is_a?(Hash) ||
|
77
77
|
defined?(Rails) && Rails.version.to_i >= 5 && params[:filter].is_a?(ActionController::Parameters)
|
@@ -86,8 +86,8 @@ module APIHelper::Filterable
|
|
86
86
|
# escape string to prevent SQL injection
|
87
87
|
field = resource.connection.quote_string(field)
|
88
88
|
|
89
|
-
next if resource.columns_hash[field].blank?
|
90
|
-
field_type = resource.columns_hash[field].type
|
89
|
+
next if ignore_unknown_fields && resource.columns_hash[field].blank?
|
90
|
+
field_type = resource.columns_hash[field] && resource.columns_hash[field].type || :unknown
|
91
91
|
|
92
92
|
# if a function is used
|
93
93
|
if func = condition.match(/(?<function>[^\(\)]+)\((?<param>.*)\)/)
|
data/lib/api_helper/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Neson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -202,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
202
202
|
version: '0'
|
203
203
|
requirements: []
|
204
204
|
rubyforge_project:
|
205
|
-
rubygems_version: 2.
|
205
|
+
rubygems_version: 2.4.6
|
206
206
|
signing_key:
|
207
207
|
specification_version: 4
|
208
208
|
summary: Helpers for creating standard web API.
|