Class: Tbone::Devise::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/tbone/devise/engine.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



13
14
15
# File 'lib/tbone/devise/engine.rb', line 13

def initialize(app)
  @app = app       
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/tbone/devise/engine.rb', line 16

def call(env)      
  warden = env['warden']
  return @app.call(env) if env['REQUEST_PATH'] =~ /^\/assets/
  user = warden.authenticate
  m = self
  Tbone.configure do |c|
    c.add_params currentUser: m.render_user(user || User.new)
    c.add_params guestUser: m.render_user(User.new)
  end
  @app.call(env)
end

#render_user(user) ⇒ Object



27
28
29
# File 'lib/tbone/devise/engine.rb', line 27

def render_user(user)
  Rabl.render(user, 'users/show', view_path: 'app/views', format: :hash)
end