class GrapeTokenAuth::ResourceFinder
Attributes
finder_key[R]
params[R]
resource_class[R]
scope[R]
Public Class Methods
find(scope, params)
click to toggle source
# File lib/grape_token_auth/resource/resource_finder.rb, line 11 def self.find(scope, params) new(scope, params).find_resource end
new(scope, params)
click to toggle source
# File lib/grape_token_auth/resource/resource_finder.rb, line 4 def initialize(scope, params) @scope = scope @params = params set_resource_class set_finder_key end
Public Instance Methods
find_resource()
click to toggle source
# File lib/grape_token_auth/resource/resource_finder.rb, line 15 def find_resource return unless finder_key find_resource_by_key end
Private Instance Methods
configuration()
click to toggle source
# File lib/grape_token_auth/resource/resource_finder.rb, line 45 def configuration GrapeTokenAuth.configuration end
find_resource_by_key()
click to toggle source
# File lib/grape_token_auth/resource/resource_finder.rb, line 29 def find_resource_by_key query_value = params[finder_key] || params[finder_key.to_s] query = "#{finder_key} = ? AND provider='email'" insensitive_keys = resource_class.case_insensitive_keys if insensitive_keys && insensitive_keys.include?(finder_key) query_value.downcase! end resource_class.where(query, query_value).first # if ActiveRecord::Base.connection.adapter_name.downcase.starts_with? 'mysql' # q = "BINARY " + q # end end
set_finder_key()
click to toggle source
# File lib/grape_token_auth/resource/resource_finder.rb, line 24 def set_finder_key auth_keys = configuration.authentication_keys @finder_key = (params.keys.map(&:to_sym) & auth_keys).first end
set_resource_class()
click to toggle source
# File lib/grape_token_auth/resource/resource_finder.rb, line 49 def set_resource_class @resource_class = configuration.scope_to_class(scope) fail(ScopeUndefinedError.new(scope)) unless resource_class end