Class: SchemaErd::App

Inherits:
Object
  • Object
show all
Defined in:
lib/schema_erd.rb

Instance Method Summary collapse

Constructor Details

#initialize(schema_path:) ⇒ App

Returns a new instance of App.



154
155
156
# File 'lib/schema_erd.rb', line 154

def initialize(schema_path:)
  @schema_path = schema_path
end

Instance Method Details

#call(env) ⇒ Object



158
159
160
161
162
163
164
165
166
# File 'lib/schema_erd.rb', line 158

def call(env)
  return not_found unless env["REQUEST_METHOD"] == "GET"

  schema = Parser.call(File.read(schema_path))
  body = Page.new(schema:, schema_path:).render
  [ 200, headers, [ body ] ]
rescue Errno::ENOENT => error
  [ 500, headers, [ "<h1>Schema unavailable</h1><pre>#{Html.escape(error.message)}</pre>" ] ]
end