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 = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n<head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>\n <title>CloudKit</title>\n <style type=\"text/css\">\nbody {\n font-family: 'Helvetica', 'Arial', san-serif;\n font-size: 15px;\n margin: 0;\n padding: 0;\n color: #222222;\n}\nh1 {\n font-family: 'Helvetica Neue', 'Helvetica', 'Arial', san-serif;\n font-size: 73px;\n font-weight: bold;\n line-height: 28px;\n margin: 20px 0px 20px 0px;\n}\n.wrapper {\n width: 500px;\n margin: 0 auto;\n clear: both;\n}\np {\n margin-top: 0px;\n line-height: 1.5em;\n}\n#header {\n background-color: #ffffcc;\n display: block;\n padding: 2px 0;\n margin: 35px 0px 10px 0px;\n border-top: 1px solid #ffcc66;\n border-bottom: 1px solid #ffcc66;\n}\na {\n color: #6b8df2;\n text-decoration: none;\n}\n.meta {\n padding: 7px 7px 7px 7px;\n background-color: #ffccff;\n border-top: 1px solid #cc99ff;\n border-bottom: 1px solid #cc99ff;\n font-size: 14px;\n display: block;\n margin: 10px 0px 10px 0px;\n}\n </style>\n</head>\n<body>\n <div id=\"header\">\n<div class=\"wrapper\">\n <h1>CloudKit</h1>\n</div>\n </div>\n <div class=\"meta\">\n<p class=\"wrapper\">\n This page is appearing because you have not set up a default app in your\n rackup file. To learn more about CloudKit, check out\n <a href=\"http://getcloudkit.com\">the site</a>.\n</p>\n </div>\n</body>\n</html>\n" end |