rest_framework 0.3.0 → 0.3.2

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: 5a4c53fa557df9090c749745efce556214252b76e2115df09917970e9a9c8b5e
4
- data.tar.gz: 5c33946ae697618f726532e9b45056f2e112d3f81f6efb5c9a37ab8d9b3b002e
3
+ metadata.gz: cb9085823972b6991c739761eb1ec47ce012e9b0c40e0215199b1cc1f2e681c0
4
+ data.tar.gz: 7c211b54982077d586d35cd0c04401f1e7ec54cd5363234f5832651f605aee5d
5
5
  SHA512:
6
- metadata.gz: ddfd6544b96284e871684d2f448e622631bd88631ea78ebe4170d2ff2fe4f1654901ef86a96584e3c5d0a2538bcef5d29f85152795aa689df58fc98cb05f7b3b
7
- data.tar.gz: 1ab60515fcf543c0df574a6cf3913648736d19d559b1d9fbe55f891ce3e6926026357369580430ada33b6e294a081d8058b297bb3f146b3d17f4671b10683d55
6
+ metadata.gz: a92b41406fa3d2723fe29e53ff38c129453b3357e6d21f51fb79de797812a2d20ea0dd5936ace48834084d00887658daf7be63bbb65e98d7cb7eee21fbe2fd89
7
+ data.tar.gz: 652d9e6c68f1688202d7ee52617bb73491f358afffcd99960bda6edc3acf2a6dd2942e278bcfeb7e86876754f16d9b8911af716b61eb179f021188ecd61e9dc8
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.2
@@ -182,9 +182,9 @@ module RESTFramework::BaseControllerMixin
182
182
  hkwargs = kwargs.merge(html_kwargs)
183
183
  begin
184
184
  render(**hkwargs)
185
- rescue ActionView::MissingTemplate # fallback to rest_framework layout/view
185
+ rescue ActionView::MissingTemplate # fallback to rest_framework layout
186
186
  hkwargs[:layout] = "rest_framework"
187
- hkwargs[:template] = "rest_framework/default"
187
+ hkwargs[:html] = ''
188
188
  render(**hkwargs)
189
189
  end
190
190
  }
@@ -37,6 +37,9 @@ module RESTFramework::BaseModelControllerMixin
37
37
  filterset_fields: nil,
38
38
  ordering_fields: nil,
39
39
  ordering_query_param: 'ordering',
40
+ search_fields: nil,
41
+ search_query_param: 'search',
42
+ search_case_sensitive: false,
40
43
 
41
44
  # Other misc attributes.
42
45
  create_from_recordset: true, # Option for `recordset.create` vs `Model.create` behavior.
@@ -89,6 +92,11 @@ module RESTFramework::BaseModelControllerMixin
89
92
  return self.class.ordering_fields&.map(&:to_s) || self.get_fields
90
93
  end
91
94
 
95
+ # Get a list of search fields for the current action.
96
+ def get_search_fields
97
+ return self.class.search_fields&.map(&:to_s) || self.get_fields
98
+ end
99
+
92
100
  # Get a list of parameters allowed for the current action.
93
101
  def get_allowed_parameters
94
102
  return _get_specific_action_config(:allowed_action_parameters, :allowed_parameters)&.map(&:to_s)
@@ -15,7 +15,7 @@ class RESTFramework::ModelFilter < RESTFramework::BaseFilter
15
15
  # Filter params for keys allowed by the current action's filterset_fields/fields config.
16
16
  def _get_filter_params
17
17
  fields = @controller.send(:get_filterset_fields)
18
- return @controller.request.query_parameters.select { |p|
18
+ return @controller.request.query_parameters.select { |p, _|
19
19
  fields.include?(p)
20
20
  }.to_h.symbolize_keys # convert from HashWithIndifferentAccess to Hash w/keys
21
21
  end
@@ -71,6 +71,20 @@ class RESTFramework::ModelOrderingFilter < RESTFramework::BaseFilter
71
71
  end
72
72
 
73
73
 
74
- # TODO: implement searching within fields rather than exact match filtering (ModelFilter)
75
- # class RESTFramework::ModelSearchFilter < RESTFramework::BaseFilter
76
- # end
74
+ # Multi-field text searching on models.
75
+ class RESTFramework::ModelSearchFilter < RESTFramework::BaseFilter
76
+ # Filter data according to the request query parameters.
77
+ def get_filtered_data(data)
78
+ fields = @controller.send(:get_search_fields)
79
+ search = @controller.request.query_parameters[@controller.send(:search_query_param)]
80
+
81
+ # Ensure we use array conditions to prevent SQL injection.
82
+ unless search.blank?
83
+ return data.where(fields.map { |f|
84
+ "CAST(#{f} AS text) #{@controller.send(:search_case_sensitive) ? "LIKE" : "ILIKE"} ?"
85
+ }.join(' OR '), *(["%#{search}%"] * fields.length))
86
+ end
87
+
88
+ return data
89
+ end
90
+ end
@@ -83,6 +83,7 @@ class RESTFramework::PageNumberPaginator < RESTFramework::BasePaginator
83
83
  return {
84
84
  count: @count,
85
85
  page: @page_number,
86
+ page_size: @page_size,
86
87
  total_pages: @total_pages,
87
88
  results: serialized_page,
88
89
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest_framework
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregory N. Schmit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-11 00:00:00.000000000 Z
11
+ date: 2021-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -37,7 +37,6 @@ files:
37
37
  - app/views/layouts/rest_framework.html.erb
38
38
  - app/views/rest_framework/_head.html.erb
39
39
  - app/views/rest_framework/_routes.html.erb
40
- - app/views/rest_framework/default.html.erb
41
40
  - lib/rest_framework.rb
42
41
  - lib/rest_framework/controller_mixins.rb
43
42
  - lib/rest_framework/controller_mixins/base.rb
@@ -73,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
72
  - !ruby/object:Gem::Version
74
73
  version: '0'
75
74
  requirements: []
76
- rubygems_version: 3.0.9
75
+ rubygems_version: 3.1.4
77
76
  signing_key:
78
77
  specification_version: 4
79
78
  summary: A framework for DRY RESTful APIs in Ruby on Rails.
File without changes