Class: Hecks::Forms::App

Inherits:
Object
  • Object
show all
Defined in:
lib/hecks/forms/app.rb

Overview

The content-negotiated router: GET /Banking/Account/Overdrawn.html renders the query view built in this directory; the identical path with no extension (or .json) dispatches the SAME ask through Runtime::Dispatcher#query and answers with its raw result — one route, two representations, exactly the "change the file format on the route" mechanism this was built around (docs/command-form-and-query-form-bluebook.md).

A plain Rack app (#call(env)) — no Sinatra, no Rails. rack itself is a LAZY dependency the same way pg/oauth2/aws-sdk-lambda are for their own adapters (see the Gemfile's own comment) : a project that never boots this file never needs it installed.

Defined Under Namespace

Classes: RouteNotFound

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(registry:, exposed:, dispatcher: nil) ⇒ App

Returns a new instance of App.



35
36
37
38
39
# File 'lib/hecks/forms/app.rb', line 35

def initialize(registry:, exposed:, dispatcher: nil)
  @registry   = registry
  @exposed    = exposed
  @dispatcher = dispatcher || Runtime::Dispatcher.new(registry)
end

Class Method Details

.for(registry:, app_name:) ⇒ Object



28
29
30
31
32
33
# File 'lib/hecks/forms/app.rb', line 28

def self.for(registry:, app_name:)
  config = Forms.config(app_name) ||
           raise(ArgumentError, "no app #{app_name.inspect} configured — " \
                                "call Hecks::Forms.configure(#{app_name.inspect}) { expose \"...\" } first")
  new(registry: registry, exposed: config.exposes)
end

Instance Method Details

#call(env) ⇒ Object



41
42
43
44
45
46
# File 'lib/hecks/forms/app.rb', line 41

def call(env)
  request = Rack::Request.new(env)
  route(request)
rescue RouteNotFound => e
  respond(404, "text/plain", e.message)
end