Class: Foobara::CommandConnector::AuthenticatorSelector

Inherits:
Authenticator show all
Defined in:
foobara-0.0.125/projects/command_connectors/src/authenticator_selector.rb

Overview

TODO: should switch to a processor and give errors if the authenticator header is malformed

Instance Attribute Summary collapse

Attributes inherited from Authenticator

#block

Attributes inherited from Value::Processor

#created_in_namespace, #declaration_data, #parent_declaration_data

Instance Method Summary collapse

Methods inherited from Authenticator

#explanation, #symbol, #to_proc, #transform

Methods inherited from Value::Transformer

create, error_classes, foobara_manifest, #process_value, subclass, #transform

Methods inherited from Value::Processor

#always_applicable?, #applicable?, #attribute_name, #build_error, default_declaration_data, #dup_processor, error_class, error_classes, #error_context, #error_message, #error_path, foobara_manifest, #foobara_manifest, #inspect, instance, #method_missing, #name, new_with_agnostic_args, #possible_errors, #priority, #process_outcome, #process_outcome!, #process_value, #process_value!, processor_name, requires_declaration_data?, requires_parent_declaration_data?, #respond_to_missing?, #runner, symbol

Methods included from IsManifestable

#foobara_domain, #foobara_manifest, #foobara_organization, #scoped_clear_caches

Methods included from Foobara::Concern

foobara_class_methods_module_for, foobara_concern?, included

Constructor Details

#initialize(authenticators:, symbol: nil, explanation: nil, &block) ⇒ AuthenticatorSelector

Returns a new instance of AuthenticatorSelector.



9
10
11
12
13
14
15
16
17
18
# File 'foobara-0.0.125/projects/command_connectors/src/authenticator_selector.rb', line 9

def initialize(authenticators:, symbol: nil, explanation: nil, &block)
  self.authenticators = authenticators

  symbol ||= authenticators.map(&:symbol).map(&:to_s).join("_or_").to_sym
  explanation ||= authenticators.map(&:explanation).join(", or ")

  super(symbol:, explanation:)

  @block = block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Foobara::Value::Processor

Instance Attribute Details

#authenticatorsObject

Returns the value of attribute authenticators.



7
8
9
# File 'foobara-0.0.125/projects/command_connectors/src/authenticator_selector.rb', line 7

def authenticators
  @authenticators
end

Instance Method Details

#authenticate(request) ⇒ Object



24
25
26
# File 'foobara-0.0.125/projects/command_connectors/src/authenticator_selector.rb', line 24

def authenticate(request)
  selector.process_value!(request)
end

#relevant_entity_classes(request) ⇒ Object



28
29
30
31
32
33
34
# File 'foobara-0.0.125/projects/command_connectors/src/authenticator_selector.rb', line 28

def relevant_entity_classes(request)
  outcome = selector.processor_for(request)

  if outcome.success?
    outcome.result&.relevant_entity_classes(request)
  end
end

#selectorObject



20
21
22
# File 'foobara-0.0.125/projects/command_connectors/src/authenticator_selector.rb', line 20

def selector
  @selector ||= Value::Processor::Selection.new(processors: authenticators, error_if_none_applicable: false)
end