Class: Apia::Definitions::Authenticator

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

Constant Summary collapse

TYPES =
[:bearer, :anonymous].freeze

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

#actionObject

Returns the value of attribute action.



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

def action
  @action
end

#potential_errorsObject (readonly)

Returns the value of attribute potential_errors.



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

def potential_errors
  @potential_errors
end

#scope_validatorObject

Returns the value of attribute scope_validator.



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

def scope_validator
  @scope_validator
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#dslObject



22
23
24
# File 'lib/apia/definitions/authenticator.rb', line 22

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

#setupObject



17
18
19
20
# File 'lib/apia/definitions/authenticator.rb', line 17

def setup
  @id = id
  @potential_errors = []
end

#validate(errors) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/apia/definitions/authenticator.rb', line 26

def validate(errors)
  if @type.nil?
    errors.add self, 'MissingType', 'A type must be defined for authenticators'
  elsif !TYPES.include?(@type)
    errors.add self, 'InvalidType', "The type must be one of #{TYPES.join(', ')} (was: #{@type.inspect})"
  end

  if @action && !@action.is_a?(Proc)
    errors.add self, 'InvalidAction', 'The action provided must be a Proc'
  end

  @potential_errors.each_with_index do |error, index|
    unless error.respond_to?(:ancestors) && error.ancestors.include?(Apia::Error)
      errors.add self, 'InvalidPotentialError', "Potential error at index #{index} must be a class that inherits from Apia::Error"
    end
  end
end