@@ -804,14 +804,17 @@ class PersonResource < BaseResource
804804 has_one :preferences
805805 has_one :hair_cut
806806
807- filter :name , verify : -> ( values , _context ) {
807+ filter :name , verify : :verify_name_filter
808+
809+ def self . verify_name_filter ( values , _context )
808810 values . each do |value |
809811 if value . length < 3
810812 raise JSONAPI ::Exceptions ::InvalidFilterValue . new ( :name , value )
811813 end
812814 end
813815 return values
814- }
816+ end
817+
815818end
816819
817820class SpecialBaseResource < BaseResource
@@ -1280,15 +1283,7 @@ class BookResource < JSONAPI::Resource
12801283 has_many :aliased_comments , class_name : 'BookComments' , relation_name : :approved_book_comments
12811284
12821285 filters :book_comments
1283- filter :banned , apply : -> ( records , value , options ) {
1284- context = options [ :context ]
1285- current_user = context ? context [ :current_user ] : nil
1286-
1287- # Only book admins my filter for banned books
1288- if current_user && current_user . book_admin
1289- records . where ( 'books.banned = ?' , value [ 0 ] == 'true' )
1290- end
1291- }
1286+ filter :banned , apply : :apply_filter_banned
12921287
12931288 class << self
12941289 def books
@@ -1310,6 +1305,17 @@ def records(options = {})
13101305 end
13111306 records
13121307 end
1308+
1309+ def apply_filter_banned ( records , value , options )
1310+ context = options [ :context ]
1311+ current_user = context ? context [ :current_user ] : nil
1312+
1313+ # Only book admins might filter for banned books
1314+ if current_user && current_user . book_admin
1315+ records . where ( 'books.banned = ?' , value [ 0 ] == 'true' )
1316+ end
1317+ end
1318+
13131319 end
13141320 end
13151321
0 commit comments