Module: OpenStax::Api::RoutingMapperIncludes

Defined in:
lib/openstax/api/routing_mapper_includes.rb

Instance Method Summary collapse

Instance Method Details

#api(version, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/openstax/api/routing_mapper_includes.rb', line 6

def api(version, options = {})
  api_namespace = (options.delete(:namespace) || 'api').to_s
  routing_error_app = options.delete(:routing_error_app) || \
                        OpenStax::Api.configuration.routing_error_app
  constraints = Constraints.new(version: version, default: options.delete(:default))

  namespace api_namespace, defaults: {format: 'json'}.merge(options) do
    scope(except: [:new, :edit], module: version, constraints: constraints) do
      root to: '/apipie/apipies#index', defaults: {format: 'html', version: version.to_s}

      yield

      match '/*options', via: [:options], to: '/openstax/api/v1/api#options'
      match '/*other', via: [:all], to: routing_error_app
    end
  end
end