Class: Apia::Definitions::API

Inherits:
Apia::Definition show all
Defined in:
lib/apia/definitions/api.rb

Instance Attribute Summary collapse

Attributes inherited from Apia::Definition

#description, #id, #name, #schema

Instance Method Summary collapse

Methods inherited from Apia::Definition

#initialize, #schema?

Constructor Details

This class inherits a constructor from Apia::Definition

Instance Attribute Details

#authenticatorObject

Returns the value of attribute authenticator.



12
13
14
# File 'lib/apia/definitions/api.rb', line 12

def authenticator
  @authenticator
end

#controllersObject (readonly)

Returns the value of attribute controllers.



13
14
15
# File 'lib/apia/definitions/api.rb', line 13

def controllers
  @controllers
end

#exception_handlersObject (readonly)

Returns the value of attribute exception_handlers.



15
16
17
# File 'lib/apia/definitions/api.rb', line 15

def exception_handlers
  @exception_handlers
end

#route_setObject (readonly)

Returns the value of attribute route_set.



14
15
16
# File 'lib/apia/definitions/api.rb', line 14

def route_set
  @route_set
end

#scopesObject (readonly)

Returns the value of attribute scopes.



16
17
18
# File 'lib/apia/definitions/api.rb', line 16

def scopes
  @scopes
end

Instance Method Details

#dslObject



25
26
27
# File 'lib/apia/definitions/api.rb', line 25

def dsl
  @dsl ||= DSLs::API.new(self)
end

#setupObject



18
19
20
21
22
23
# File 'lib/apia/definitions/api.rb', line 18

def setup
  @route_set = RouteSet.new
  @controllers = {}
  @exception_handlers = HookSet.new
  @scopes = {}
end

#validate(errors) ⇒ void

This method returns an undefined value.

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

Parameters:



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 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