Class: Jets::Shim::Maintenance

Inherits:
Object
  • Object
show all
Extended by:
Util::Truthy, Memoist
Defined in:
lib/jets/shim/maintenance.rb

Class Method Summary collapse

Methods included from Util::Truthy

truthy?

Class Method Details

.appObject



7
8
9
# File 'lib/jets/shim/maintenance.rb', line 7

def app
  self
end

.bodyObject



21
22
23
# File 'lib/jets/shim/maintenance.rb', line 21

def body
  IO.read(maintenance_file)
end

.call(env) ⇒ Object



11
12
13
# File 'lib/jets/shim/maintenance.rb', line 11

def call(env)
  [503, {"Content-Type" => content_type}, [body]]
end

.content_typeObject

IE: application/json; charset=utf-8 IE: text/html



17
18
19
# File 'lib/jets/shim/maintenance.rb', line 17

def content_type
  maintenance_file.end_with?("json") ? "application/json" : "text/html"
end

.enabled?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/jets/shim/maintenance.rb', line 32

def enabled?
  truthy?(ENV["JETS_MAINTENANCE"])
end

.maintenance_fileObject



25
26
27
28
29
# File 'lib/jets/shim/maintenance.rb', line 25

def maintenance_file
  default_path = "#{__dir__}/maintenance/maintenance.html"
  paths = %w[public/maintenance.html public/maintenance.json]
  paths.find { |path| File.exist?(path) } || default_path
end