Class: Rack::Builder
Instance Method Summary collapse
- #cloudkit_to_app ⇒ Object
-
#contain(*args) ⇒ Object
Setup resource collections hosted behind OAuth and OpenID auth filters.
-
#expose(*args) ⇒ Object
Setup resource collections without authentication.
-
#to_app ⇒ Object
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.
-
#welcome ⇒ Object
:nodoc:.
Instance Method Details
#cloudkit_to_app ⇒ Object
3 |
# File 'lib/cloudkit/rack/builder.rb', line 3 alias_method :cloudkit_to_app, :to_app |
#contain(*args) ⇒ Object
Setup resource collections hosted behind OAuth and OpenID auth filters.
Example
contain :notes, :projects
25 26 27 28 29 30 31 32 33 |
# File 'lib/cloudkit/rack/builder.rb', line 25 def contain(*args) @ins << lambda do |app| Rack::Session::Pool.new( CloudKit::OAuthFilter.new( CloudKit::OpenIDFilter.new( CloudKit::Service.new(app, :collections => args.to_a)))) end @last_cloudkit_id = @ins.last.object_id end |
#expose(*args) ⇒ Object
Setup resource collections without authentication.
Example
expose :notes, :projects
40 41 42 43 44 45 |
# File 'lib/cloudkit/rack/builder.rb', line 40 def expose(*args) @ins << lambda do |app| CloudKit::Service.new(app, :collections => args.to_a) end @last_cloudkit_id = @ins.last.object_id end |
#to_app ⇒ Object
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.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/cloudkit/rack/builder.rb', line 8 def to_app default_app = lambda do |env| if (env['PATH_INFO'] == '/') Rack::Response.new(welcome).finish else Rack::Response.new('not found', 404).finish end end @ins << default_app if @last_cloudkit_id == @ins.last.object_id cloudkit_to_app end |
#welcome ⇒ Object
:nodoc:
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/cloudkit/rack/builder.rb', line 47 def welcome #:nodoc: doc = <<HTML <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>CloudKit</title> <style type="text/css"> body { font-family: 'Helvetica', 'Arial', san-serif; font-size: 15px; margin: 0; padding: 0; color: #222222; } h1 { font-family: 'Helvetica Neue', 'Helvetica', 'Arial', san-serif; font-size: 73px; font-weight: bold; line-height: 28px; margin: 20px 0px 20px 0px; } .wrapper { width: 500px; margin: 0 auto; clear: both; } p { margin-top: 0px; line-height: 1.5em; } #header { background-color: #ffffcc; display: block; padding: 2px 0; margin: 35px 0px 10px 0px; border-top: 1px solid #ffcc66; border-bottom: 1px solid #ffcc66; } a { color: #6b8df2; text-decoration: none; } .meta { padding: 7px 7px 7px 7px; background-color: #ffccff; border-top: 1px solid #cc99ff; border-bottom: 1px solid #cc99ff; font-size: 14px; display: block; margin: 10px 0px 10px 0px; } </style> </head> <body> <div id="header"> <div class="wrapper"> <h1>CloudKit</h1> </div> </div> <div class="meta"> <p class="wrapper"> This page is appearing because you have not set up a default app in your rackup file. To learn more about CloudKit, check out <a href="http://getcloudkit.com">the site</a>. </p> </div> </body> </html> HTML end |