class Rack::ServiceApiVersioning::ServiceComponentDescriber
Middleware that, given a “service name” parameter, will read descriptive data from a supplied repository regarding the named service, format that data as a JSON string, assign it to the `COMPONENT_DESCRIPTION` environment variable, and pass the updated environment along to the next link in the Rack
call chain (app or more middleware). If there is no data for the named service in the repository, this middleware will halt execution with a 404 (Not Found).
Also bear in mind that both usual parameters (`repository` and `service_name`) are supplied *by the AVIDA,* which should know what those “ought” to be.
Middlware to query and encode data on a named service, making it available to later entries in the middleware chain via an environment variable.
Constants
- DEFAULT_ENV_KEYS
Attributes
Public Class Methods
# File lib/rack/service_api_versioning/service_component_describer.rb, line 26 def initialize(app, repository:, service_name:, env_keys: DEFAULT_ENV_KEYS) @app = app @env_keys = env_keys @repository = repository @service_name = service_name self end
Public Instance Methods
# File lib/rack/service_api_versioning/service_component_describer.rb, line 35 def call(env) env = update_env(env) verify_datum_set(env) { |app_env| app.call app_env } end
Private Instance Methods
# File lib/rack/service_api_versioning/service_component_describer.rb, line 44 def first_record repository.find(name: service_name).first end
# File lib/rack/service_api_versioning/service_component_describer.rb, line 48 def result_key env_keys[:result] end
# File lib/rack/service_api_versioning/service_component_describer.rb, line 52 def update_env(env) datum = first_record env[result_key] = JSON.dump(datum) if datum env end
# File lib/rack/service_api_versioning/service_component_describer.rb, line 58 def verify_datum_set(env) verify_found(env) || yield(env) end
# File lib/rack/service_api_versioning/service_component_describer.rb, line 62 def verify_found(env) return nil if env[result_key] ReportServiceNotFound.call(service_name) end