Class Rack::Builder

  1. lib/cloudkit/rack/builder.rb
Parent: Object

Methods

public instance

  1. cloudkit_to_app
  2. contain
  3. expose
  4. to_app

Public instance methods

cloudkit_to_app ()

Alias for to_app

contain (*args)

Setup resource collections hosted behind OAuth and OpenID auth filters.

Example

contain :notes, :projects
[show source]
    # File lib/cloudkit/rack/builder.rb, line 25
25:     def contain(*args)
26:       @ins << lambda do |app|
27:         Rack::Session::Pool.new(
28:           CloudKit::OAuthFilter.new(
29:             CloudKit::OpenIDFilter.new(
30:               CloudKit::Service.new(app, :collections => args.to_a))))
31:       end
32:       @last_cloudkit_id = @ins.last.object_id
33:     end
expose (*args)

Setup resource collections without authentication.

Example

expose :notes, :projects
[show source]
    # File lib/cloudkit/rack/builder.rb, line 40
40:     def expose(*args)
41:       @ins << lambda do |app|
42:         CloudKit::Service.new(app, :collections => args.to_a)
43:       end
44:       @last_cloudkit_id = @ins.last.object_id
45:     end
to_app ()

Extends Rack::Builder’s to_app method to detect if the last piece of middleware in the stack is a CloudKit shortcut (contain or expose), adding a default developer page at the root and a 404 everywhere else.

[show source]
    # File lib/cloudkit/rack/builder.rb, line 8
 8:     def to_app
 9:       default_app = lambda do |env|
10:         if (env['PATH_INFO'] == '/')
11:           Rack::Response.new(welcome).finish
12:         else
13:           Rack::Response.new('not found', 404).finish
14:         end
15:       end
16:       @ins << default_app if @last_cloudkit_id == @ins.last.object_id
17:       cloudkit_to_app
18:     end