Class: Blade::RackAdapter

Inherits:
Object
  • Object
show all
Includes:
RackRouter
Defined in:
lib/blade/rack/adapter.rb

Constant Summary

Constants included from RackRouter

Blade::RackRouter::DEFAULT

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRackAdapter

Returns a new instance of RackAdapter.



15
16
17
# File 'lib/blade/rack/adapter.rb', line 15

def initialize
  Blade.initialize!
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



13
14
15
# File 'lib/blade/rack/adapter.rb', line 13

def env
  @env
end

#requestObject (readonly)

Returns the value of attribute request.



13
14
15
# File 'lib/blade/rack/adapter.rb', line 13

def request
  @request
end

Instance Method Details

#call(env) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/blade/rack/adapter.rb', line 19

def call(env)
  @env = env
  @request = Rack::Request.new(env)

  route = find_route(request.path_info)
  base_path, action = route.values_at(:base_path, :action)

  rewrite_path!(base_path)

  case
  when action[:environment]
    environment(action[:environment]).call(env)
  when action[:to]
    send(action[:to])
  end
end

#indexObject



36
37
38
39
40
41
# File 'lib/blade/rack/adapter.rb', line 36

def index
  request.path_info = "/index.html"
  response = environment(:blade).call(env)
  response = add_session_cookie(response) if needs_session_cookie?
  response.to_a
end

#redirect_to_indexObject



43
44
45
46
47
48
49
# File 'lib/blade/rack/adapter.rb', line 43

def redirect_to_index
  Rack::Response.new.tap do |response|
    path = request.path
    path = path + "/" unless path.last == "/"
    response.redirect(path)
  end.to_a
end

#websocketObject



51
52
53
# File 'lib/blade/rack/adapter.rb', line 51

def websocket
  faye_adapter.call(env)
end