class Turnout::MaintenancePage::Base
Attributes
reason[R]
Public Class Methods
extension()
click to toggle source
Override with a file extension value like 'html' or 'json'
# File lib/turnout/maintenance_page/base.rb, line 23 def self.extension raise NotImplementedError, '.extension must be overridden in subclasses' end
media_types()
click to toggle source
Override with an array of media type strings. i.e. text/html
# File lib/turnout/maintenance_page/base.rb, line 17 def self.media_types raise NotImplementedError, '.media_types must be overridden in subclasses' end
new(reason = nil, options = {})
click to toggle source
# File lib/turnout/maintenance_page/base.rb, line 6 def initialize(reason = nil, options = {}) @options = options.is_a?(Hash) ? options : {} @reason = reason end
Protected Class Methods
inherited(subclass)
click to toggle source
# File lib/turnout/maintenance_page/base.rb, line 34 def self.inherited(subclass) MaintenancePage.all << subclass end
Public Instance Methods
custom_path()
click to toggle source
# File lib/turnout/maintenance_page/base.rb, line 28 def custom_path Pathname.new(Turnout.config.maintenance_pages_path).join(filename) end
extension()
click to toggle source
# File lib/turnout/maintenance_page/base.rb, line 26 def extension() self.class.extension end
media_types()
click to toggle source
# File lib/turnout/maintenance_page/base.rb, line 20 def media_types() self.class.media_types end
rack_response(code = nil, retry_after = nil)
click to toggle source
# File lib/turnout/maintenance_page/base.rb, line 11 def rack_response(code = nil, retry_after = nil) code ||= Turnout.config.default_response_code [code, headers(retry_after), body] end
Protected Instance Methods
body()
click to toggle source
# File lib/turnout/maintenance_page/base.rb, line 49 def body [content] end
content()
click to toggle source
# File lib/turnout/maintenance_page/base.rb, line 53 def content file_content.gsub(/{{\s?reason\s?}}/, reason) end
default_path()
click to toggle source
# File lib/turnout/maintenance_page/base.rb, line 69 def default_path File.expand_path("../../../../public/#{filename}", __FILE__) end
file_content()
click to toggle source
# File lib/turnout/maintenance_page/base.rb, line 57 def file_content File.read(path) end
filename()
click to toggle source
# File lib/turnout/maintenance_page/base.rb, line 74 def filename "maintenance.#{extension}" end
headers(retry_after = nil)
click to toggle source
# File lib/turnout/maintenance_page/base.rb, line 38 def headers(retry_after = nil) headers = {'Content-Type' => media_types.first, 'Content-Length' => length} # Include the Retry-After header unless it wasn't specified headers['Retry-After'] = retry_after.to_s unless retry_after.nil? headers end
length()
click to toggle source
# File lib/turnout/maintenance_page/base.rb, line 45 def length content.bytesize.to_s end
path()
click to toggle source
# File lib/turnout/maintenance_page/base.rb, line 61 def path if File.exist? custom_path custom_path else default_path end end