Class: Stargate::Server::Engine::Sinatra
- Inherits:
-
Object
- Object
- Stargate::Server::Engine::Sinatra
- Includes:
- Gallus::Logging
- Defined in:
- lib/stargate/server/engine/sinatra.rb
Defined Under Namespace
Modules: Helpers
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(registry) ⇒ Sinatra
constructor
A new instance of Sinatra.
Constructor Details
#initialize(registry) ⇒ Sinatra
Returns a new instance of Sinatra.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/stargate/server/engine/sinatra.rb', line 9 def initialize(registry) require 'sinatra/base' logger = log @app = ::Sinatra.new do helpers Helpers registry.each do |version_number, actual_registry| caller = Caller.new(actual_registry) get "/v#{version_number}/definitions" do log.debug("Serving registry definitions") content_type(response_codec.content_type) response_codec.encode(actual_registry) end post "/v#{version_number}/:klass_name.:method" do |klass_name, method| args = parse_args log.debug("Executing call", class: klass_name, method: method, args: args) result = caller.call(klass_name, method, *args) content_type(response_codec.content_type) response_codec.encode(result) end end error Stargate::Server::NotFoundError do error_response(404) end error Stargate::Codec::Error do error_response(400) end error NotImplementedError do error_response(501) end error 500 do error_response(500) end end @app.set(:default_mime_type, ::Stargate::Codec::JSON.content_type) @app.set(:show_exceptions, false) @app.set(:logger, log) end |
Instance Method Details
#call(env) ⇒ Object
57 58 59 |
# File 'lib/stargate/server/engine/sinatra.rb', line 57 def call(env) @app.call(env) end |