fastapi 0.1.17 → 0.1.18

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
  SHA1:
3
- metadata.gz: 832572badad40969dcb8f6d057c0027d1715475d
4
- data.tar.gz: 5ee51023d5100554b269cb038ba86083abca8667
3
+ metadata.gz: 914c5c91b0fd3b9f2b81b4da4d27554b05d254a5
4
+ data.tar.gz: ee22069497c8ba7c7704f60bbaf8a94af1df8ce2
5
5
  SHA512:
6
- metadata.gz: 99cb06224e1c33548b2feb9c788d30f528f66dfe3c314dcc6f0930475eff980afd7213a3d9a08b5d6813bcee6be82c8758f8e50d182569e2f28640a4c5e163ca
7
- data.tar.gz: 7cd11d4be9b02ba8f1d261b35411e76ed129f924838f791c92af706b85b00249760bbde389a2fb7516937a6d37eccd5673c0fdb97f46bedfc83bd5faaae7175a
6
+ metadata.gz: 267c4b35d3474ac545f24683baa22e7e4d1012de69c4cfb7d7dad20213d59a6a0816d2c951ed9db18f80d96da1c6e192a8168dbbaf1d4870c3f82fa702040083
7
+ data.tar.gz: 57fbf90fa9d58518b669aa95acec4f9b3904199e3c24609c8e0a9b0bd02e45d2fe87b10b88281302fec53e9035fc9cf9f205d009e8a9128ee81eeadc674cedb7
data/lib/fastapi.rb CHANGED
@@ -28,12 +28,24 @@ class FastAPI
28
28
  @data = nil
29
29
  @metadata = nil
30
30
  @result_type = 0
31
+ @whitelist_fields = []
31
32
  end
32
33
 
33
34
  def inspect
34
35
  "<#{self.class}: #{@model}>"
35
36
  end
36
37
 
38
+ # Create and execute an optimized SQL query based on specified filters
39
+ #
40
+ # @param fields [Array] an array containing fields to whitelist for the SQL query
41
+ # @return [FastAPI] the current instance
42
+ def whitelist(fields = [])
43
+
44
+ @whitelist_fields.concat fields
45
+
46
+ self
47
+
48
+ end
37
49
 
38
50
  # Create and execute an optimized SQL query based on specified filters
39
51
  #
@@ -516,7 +528,7 @@ class FastAPI
516
528
  filters.each do |key, value|
517
529
  found_index = key.to_s.rindex('__')
518
530
  key_root = found_index.nil? ? key : key.to_s[0...found_index].to_sym
519
- if not [:__order, :__offset, :__count].include? key and not self_obj.fastapi_fields_whitelist.include? key_root
531
+ if not [:__order, :__offset, :__count].include? key and not self_obj.fastapi_filters_whitelist.include? key_root
520
532
  raise 'Filter "' + key.to_s + '" not supported'
521
533
  end
522
534
  end
@@ -758,7 +770,11 @@ class FastAPI
758
770
 
759
771
  model_lookup = {}
760
772
 
761
- @model.fastapi_fields.each do |field|
773
+ filter_fields = []
774
+ filter_fields.concat @model.fastapi_fields
775
+ filter_fields.concat @whitelist_fields
776
+
777
+ filter_fields.each do |field|
762
778
 
763
779
  if (@model.reflect_on_all_associations(:belongs_to).map(&:name).include? field or
764
780
  @model.reflect_on_all_associations(:has_one).map(&:name).include? field)
@@ -23,11 +23,12 @@ module FastAPIExtension
23
23
  end
24
24
 
25
25
  # Set safe fields for FastAPIInstance.safe_filter
26
+ # These are the fields that can be actively filtered by
26
27
  #
27
28
  # @param fields [Array] a list of fields in the form of symbols
28
29
  # @return [Array] the same array of fields
29
30
  def fastapi_safe_fields(fields)
30
- @fastapi_fields_whitelist = fields
31
+ @fastapi_filters_whitelist = fields
31
32
  end
32
33
 
33
34
  # Used to set any default filters for the top level fastapi response
@@ -58,8 +59,8 @@ module FastAPIExtension
58
59
  @fastapi_fields_sub or [:id]
59
60
  end
60
61
 
61
- def fastapi_fields_whitelist
62
- @fastapi_fields_whitelist or @fastapi_fields or [:id]
62
+ def fastapi_filters_whitelist
63
+ @fastapi_filters_whitelist or @fastapi_fields or [:id]
63
64
  end
64
65
 
65
66
  def fastapi_filters
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.17
4
+ version: 0.1.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Horwood