class Apia::Definitions::API

Attributes

authenticator[RW]
controllers[R]
exception_handlers[R]
route_set[R]
scopes[R]

Public Instance Methods

dsl() click to toggle source
# File lib/apia/definitions/api.rb, line 25
def dsl
  @dsl ||= DSLs::API.new(self)
end
setup() click to toggle source
# File lib/apia/definitions/api.rb, line 18
def setup
  @route_set = RouteSet.new
  @controllers = {}
  @exception_handlers = HookSet.new
  @scopes = {}
end
validate(errors) click to toggle source

Validate the API to ensure that everything within is acceptable for use

@param errors [Apia::ManifestErrors] @return [void]

# File lib/apia/definitions/api.rb, line 33
def validate(errors)
  if @authenticator && !(@authenticator.respond_to?(:ancestors) && @authenticator.ancestors.include?(Apia::Authenticator))
    errors.add self, 'InvalidAuthenticator', 'The authenticator must be a class that inherits from Apia::Authenticator'
  end

  @controllers.each do |name, controller|
    unless name.to_s =~ /\A[\w\-]+\z/i
      errors.add self, 'InvalidControllerName', "The controller name #{name} is invalid. It can only contain letters, numbers, underscores, and hyphens"
    end

    unless controller.respond_to?(:ancestors) && controller.ancestors.include?(Apia::Controller)
      errors.add self, 'InvalidController', "The controller for #{name} must be a class that inherits from Apia::Controller"
    end
  end
end