Class: Kazoo::Sinatra

Inherits:
Sinatra::Base
  • Object
show all
Includes:
App
Defined in:
lib/kazoo/sinatra.rb

Instance Method Summary collapse

Methods included from App

included, #krouter, #path, #url

Instance Method Details

#authenticate!Object



33
34
35
36
37
38
39
40
41
# File 'lib/kazoo/sinatra.rb', line 33

def authenticate!
  unless @_bouncer.authenticated?
    if @_bouncer.authenticate!
      halt 302, {'Location' => request.env['rack.url_scheme'] + '://' +request.env['HTTP_HOST']  + request.env['REQUEST_PATH']}, ''
    else
      throw(:halt, [401, "Not authorized\n"])
    end
  end
end

#call!(env) ⇒ Object



11
12
13
14
# File 'lib/kazoo/sinatra.rb', line 11

def call!(env)
  @_bouncer ||= Kazoo::Bouncer.new(env)
  super
end

#current_userObject



29
30
31
# File 'lib/kazoo/sinatra.rb', line 29

def current_user
  @_bouncer.current_user
end

#current_user=(user) ⇒ Object



24
25
26
27
# File 'lib/kazoo/sinatra.rb', line 24

def current_user=(user)
  @_bouncer.current_user = user
  user
end

#kenvObject



20
21
22
# File 'lib/kazoo/sinatra.rb', line 20

def kenv
  @request.env['kazoo'] ||= {}
end

#ksessionObject



16
17
18
# File 'lib/kazoo/sinatra.rb', line 16

def ksession
  session['kazoo'] ||= {}
end

#render(engine, data, options = {}, *args) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/kazoo/sinatra.rb', line 43

def render(engine, data, options = {}, *args)
  
  if !options[:views] && data.is_a?(Symbol) && !data.to_s.match('/')
    data = :"#{decamelize(self.class.name)}/#{data}"
    options[:layout] = :'layouts/application' if options[:layout].nil?
  end
  
  if options[:layout] && !options[:layout].to_s.match('/')
    options[:layout] = :"layouts/#{options[:layout]}"
  end
  
  super(engine, data, options, *args)
  
end