Class: Crawlable::Rack
- Inherits:
-
Object
- Object
- Crawlable::Rack
- Defined in:
- lib/crawlable/rack.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
- #feed(file) ⇒ Object
- #heroku_writable_directory ⇒ Object
-
#initialize(app) ⇒ Rack
constructor
A new instance of Rack.
- #sitemap(file) ⇒ Object
- #using_heroku?(env) ⇒ Boolean
Constructor Details
#initialize(app) ⇒ Rack
Returns a new instance of Rack.
4 5 6 |
# File 'lib/crawlable/rack.rb', line 4 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/crawlable/rack.rb', line 8 def call(env) if using_heroku?(env) || true if file = Crawlable::Sitemap.find(env['REQUEST_PATH'], heroku_writable_directory) return sitemap(file) elsif file = Crawlable::Feed.find(env['REQUEST_PATH'], heroku_writable_directory) return feed(file) end end @app.call(env) end |
#feed(file) ⇒ Object
23 24 25 |
# File 'lib/crawlable/rack.rb', line 23 def feed(file) [200, { 'Cache-Control' => 'public, max-age=86400', 'Content-Length' => File.size(file).to_s, 'Content-Type' => 'text/xml' }, IO.read(file)] end |
#heroku_writable_directory ⇒ Object
27 28 29 |
# File 'lib/crawlable/rack.rb', line 27 def heroku_writable_directory "#{Rails.root}/tmp" end |
#sitemap(file) ⇒ Object
19 20 21 |
# File 'lib/crawlable/rack.rb', line 19 def sitemap(file) [200, { 'Cache-Control' => 'public, max-age=86400', 'Content-Length' => File.size(file).to_s, 'Content-Type' => 'text/xml' }, IO.read(file)] end |
#using_heroku?(env) ⇒ Boolean
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/crawlable/rack.rb', line 31 def using_heroku?(env) if env["HEROKU"].nil? if env["HEROKU_PORT"].nil? && ENV["HEROKU_TYPE"].nil? env["HEROKU"] = false else env["HEROKU"] = true end end env["HEROKU"] == true end |