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.



11
12
13
# File 'lib/blade/rack/adapter.rb', line 11

def initialize
  Blade.initialize!
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



9
10
11
# File 'lib/blade/rack/adapter.rb', line 9

def env
  @env
end

#requestObject (readonly)

Returns the value of attribute request.



9
10
11
# File 'lib/blade/rack/adapter.rb', line 9

def request
  @request
end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/blade/rack/adapter.rb', line 15

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)

  send(action[:to])
end

#environmentObject



46
47
48
# File 'lib/blade/rack/adapter.rb', line 46

def environment
  Blade::Assets.environment.call(env)
end

#indexObject



27
28
29
30
31
32
# File 'lib/blade/rack/adapter.rb', line 27

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

#redirect_to_indexObject



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

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



42
43
44
# File 'lib/blade/rack/adapter.rb', line 42

def websocket
  faye_adapter.call(env)
end