Class: Heroku::Nav::Provider

Inherits:
Base
  • Object
show all
Defined in:
lib/heroku/nav.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

api_url, #call, #initialize, #refresh, resource, retry_upto

Constructor Details

This class inherits a constructor from Heroku::Nav::Base

Class Method Details

.fetchObject



123
124
125
# File 'lib/heroku/nav.rb', line 123

def fetch
  super('text/html')
end

.htmlObject

for non-rack use



132
133
134
# File 'lib/heroku/nav.rb', line 132

def html
  @@body ||= fetch
end

.resource_urlObject



127
128
129
# File 'lib/heroku/nav.rb', line 127

def resource_url
  "#{api_url}/v1/providers/header"
end

Instance Method Details

#can_insert?(env) ⇒ Boolean

Returns:

  • (Boolean)


137
138
139
# File 'lib/heroku/nav.rb', line 137

def can_insert?(env)
  super && env['HTTP_COOKIE'] && env['HTTP_COOKIE'].include?('heroku-nav-data')
end

#insert!Object



141
142
143
144
145
146
147
148
149
# File 'lib/heroku/nav.rb', line 141

def insert!
  if @nav
    match = @body.match(/(\<body[^\>]*\>)/i)
    if match && match.size > 0
      @body.insert(match.end(0), @nav)
      @headers['Content-Length'] = Rack::Utils.bytesize(@body).to_s
    end
  end
end