Module: GrapeDevise::API

Extended by:
ActiveSupport::Concern
Defined in:
lib/grape_devise/api.rb

Class Method Summary collapse

Class Method Details

.define_helpers(mapping) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/grape_devise/api.rb', line 6

def self.define_helpers mapping
  mapping = mapping.name.to_s

  class_eval "        def warden\n          env[\"warden\"]\n        end\n\n        def authenticate_\#{mapping}!(opts={})\n          opts[:scope] = :\#{mapping}\n          env[\"devise.allow_params_authentication\"] = true\n          if opts.delete(:force) || current_\#{mapping}.nil?\n            error!(\"401 Forbidden\", 401) unless warden.authenticate(opts)\n          end\n        end\n\n        def \#{mapping}_signed_in?\n          !!current_\#{mapping}\n        end\n\n        def current_\#{mapping}\n          @current_\#{mapping} ||= warden.authenticate(scope: :\#{mapping})\n        end\n\n        def \#{mapping}_session\n          current_\#{mapping} && warden.session(:\#{mapping})\n        end\n  METHODS\nend\n", __FILE__, __LINE__ + 1