Class: Apia::Definitions::Authenticator
- Inherits:
-
Apia::Definition
- Object
- Apia::Definition
- Apia::Definitions::Authenticator
- Defined in:
- lib/apia/definitions/authenticator.rb
Constant Summary collapse
- TYPES =
[:bearer, :anonymous].freeze
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#potential_errors ⇒ Object
readonly
Returns the value of attribute potential_errors.
-
#scope_validator ⇒ Object
Returns the value of attribute scope_validator.
-
#type ⇒ Object
Returns the value of attribute type.
Attributes inherited from Apia::Definition
#description, #id, #name, #schema
Instance Method Summary collapse
Methods inherited from Apia::Definition
Constructor Details
This class inherits a constructor from Apia::Definition
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
13 14 15 |
# File 'lib/apia/definitions/authenticator.rb', line 13 def action @action end |
#potential_errors ⇒ Object (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_validator ⇒ Object
Returns the value of attribute scope_validator.
14 15 16 |
# File 'lib/apia/definitions/authenticator.rb', line 14 def scope_validator @scope_validator end |
#type ⇒ Object
Returns the value of attribute type.
12 13 14 |
# File 'lib/apia/definitions/authenticator.rb', line 12 def type @type end |
Instance Method Details
#dsl ⇒ Object
22 23 24 |
# File 'lib/apia/definitions/authenticator.rb', line 22 def dsl @dsl ||= DSLs::Authenticator.new(self) end |
#setup ⇒ Object
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 |