Class: Interpol::StubApp::Builder
- Inherits:
-
Object
- Object
- Interpol::StubApp::Builder
- Defined in:
- lib/interpol/stub_app.rb
Overview
Private: Builds a stub sinatra app for the given interpol configuration.
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
Instance Method Summary collapse
- #build ⇒ Object
- #endpoint_definition(endpoint) ⇒ Object
-
#initialize(config) ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
#initialize(config) ⇒ Builder
Returns a new instance of Builder.
33 34 35 36 37 38 39 40 41 |
# File 'lib/interpol/stub_app.rb', line 33 def initialize(config) @app = Sinatra.new do set :interpol_config, config helpers Helpers not_found { JSON.dump(error: "The requested resource could not be found") } before { content_type "application/json;charset=utf-8" } get('/__ping') { JSON.dump(message: "Interpol stub app running.") } end end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
31 32 33 |
# File 'lib/interpol/stub_app.rb', line 31 def app @app end |
Instance Method Details
#build ⇒ Object
43 44 45 46 47 |
# File 'lib/interpol/stub_app.rb', line 43 def build @app.interpol_config.endpoints.each do |endpoint| app.send(endpoint.method, endpoint.route, &endpoint_definition(endpoint)) end end |
#endpoint_definition(endpoint) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/interpol/stub_app.rb', line 49 def endpoint_definition(endpoint) lambda do version = interpol_config.api_version_for(request.env, endpoint) example = example_for(endpoint, version) example.validate! JSON.dump(example.data) end end |