Sha256: c48409cb570ef165cc0d2447f2b4b8ec3d24dd1eec1a6c8045f58b7ae0f07779

Contents?: true

Size: 829 Bytes

Versions: 4

Compression:

Stored size: 829 Bytes

Contents

module Jets::Shim
  class Maintenance
    class << self
      extend Memoist
      include Jets::Util::Truthy

      def app
        self
      end

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

      # IE: application/json; charset=utf-8
      # IE: text/html
      def content_type
        maintenance_file.end_with?("json") ? "application/json" : "text/html"
      end

      def body
        IO.read(maintenance_file)
      end

      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
      memoize :maintenance_file

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jets-6.0.5 lib/jets/shim/maintenance.rb
jets-6.0.4 lib/jets/shim/maintenance.rb
jets-6.0.3 lib/jets/shim/maintenance.rb
jets-6.0.2 lib/jets/shim/maintenance.rb