Class: Devise::JWT::MappingInspector

Inherits:
Object
  • Object
show all
Defined in:
lib/devise/jwt/mapping_inspector.rb

Overview

Inspect and extract information from a Devise mapping

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope) ⇒ MappingInspector

Returns a new instance of MappingInspector.



9
10
11
12
# File 'lib/devise/jwt/mapping_inspector.rb', line 9

def initialize(scope)
  @scope = scope
  @mapping = Devise.mappings[scope]
end

Instance Attribute Details

#mappingObject (readonly)

Returns the value of attribute mapping.



7
8
9
# File 'lib/devise/jwt/mapping_inspector.rb', line 7

def mapping
  @mapping
end

#scopeObject (readonly)

Returns the value of attribute scope.



7
8
9
# File 'lib/devise/jwt/mapping_inspector.rb', line 7

def scope
  @scope
end

Instance Method Details

#formatsObject



48
49
50
# File 'lib/devise/jwt/mapping_inspector.rb', line 48

def formats
  JWT.config.request_formats[scope] || default_formats
end

#jwt?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/devise/jwt/mapping_inspector.rb', line 14

def jwt?
  mapping.modules.member?(:jwt_authenticatable)
end

#methods(name) ⇒ Object

:reek:ControlParameter



39
40
41
42
43
44
45
46
# File 'lib/devise/jwt/mapping_inspector.rb', line 39

def methods(name)
  method = case name
           when :sign_in      then 'POST'
           when :sign_out     then sign_out_via
           when :registration then 'POST'
           end
  Array(method)
end

#modelObject



26
27
28
# File 'lib/devise/jwt/mapping_inspector.rb', line 26

def model
  mapping.to
end

#path(name) ⇒ Object

:reek:FeatureEnvy



31
32
33
34
35
36
# File 'lib/devise/jwt/mapping_inspector.rb', line 31

def path(name)
  prefix, scope, request = path_parts(name)
  [prefix, scope, request].delete_if do |item|
    !item || item.empty?
  end.join('/').prepend('/').gsub('//', '/')
end

#registration?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/devise/jwt/mapping_inspector.rb', line 22

def registration?
  routes?(:registration)
end

#session?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/devise/jwt/mapping_inspector.rb', line 18

def session?
  routes?(:session)
end