class Apia::Definitions::Controller

Attributes

authenticator[RW]
endpoints[R]
helpers[R]

Public Instance Methods

dsl() click to toggle source
# File lib/apia/definitions/controller.rb, line 19
def dsl
  @dsl ||= DSLs::Controller.new(self)
end
setup() click to toggle source
# File lib/apia/definitions/controller.rb, line 14
def setup
  @endpoints = {}
  @helpers = {}
end
validate(errors) click to toggle source
# File lib/apia/definitions/controller.rb, line 23
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

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

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