Class: Grape::Knock::Authenticable

Inherits:
Middleware::Base
  • Object
show all
Includes:
Knock::Authenticable
Defined in:
lib/grape/knock/authenticable.rb

Instance Method Summary collapse

Constructor Details

#initialize(_, options = {}) ⇒ Authenticable

Returns a new instance of Authenticable.



10
11
12
13
# File 'lib/grape/knock/authenticable.rb', line 10

def initialize(_, options = {})
  super
  define_current_entity_getter entity_class, getter_name
end

Instance Method Details

#beforeObject



19
20
21
22
23
24
25
# File 'lib/grape/knock/authenticable.rb', line 19

def before
  authenticate

  memoization_var_name = "@_#{getter_name}"
  context.send(:instance_variable_set, memoization_var_name, send(getter_name))
  context.class.send(:define_method, getter_name) { instance_variable_get memoization_var_name }
end

#contextObject



15
16
17
# File 'lib/grape/knock/authenticable.rb', line 15

def context
  env['api.endpoint']
end