Class: Foobara::BuiltinTypes::Duck::SupportedValidators::OneOf

Inherits:
TypeDeclarations::Validator show all
Defined in:
foobara-0.0.110/projects/builtin_types/src/duck/supported_validators/one_of.rb,
foobara-0.0.110/projects/builtin_types/src/duck/supported_validators/one_of/type_declaration_extension/extend_registered_type_declaration/desugarizers/cast_one_of.rb,
foobara-0.0.110/projects/builtin_types/src/duck/supported_validators/one_of/type_declaration_extension/extend_registered_type_declaration/desugarizers/module_desugarizer.rb

Defined Under Namespace

Modules: TypeDeclarationExtension Classes: ValueNotValidError

Instance Attribute Summary

Attributes inherited from Value::Processor

#created_in_namespace, #declaration_data, #parent_declaration_data

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Concern

foobara_class_methods_module_for, foobara_concern?, included

Methods inherited from Value::Validator

#build_error, foobara_manifest, #possible_errors, #process_value

Methods inherited from Value::Processor

#always_applicable?, #attribute_name, #build_error, default_declaration_data, #dup_processor, error_class, error_classes, #error_path, foobara_manifest, #foobara_manifest, #initialize, #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?, #respond_to_missing?, #runner, symbol

Methods included from IsManifestable

#foobara_domain, #foobara_manifest, #foobara_organization, #scoped_clear_caches

Constructor Details

This class inherits a constructor from Foobara::Value::Processor

Dynamic Method Handling

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

Class Method Details

.requires_parent_declaration_data?Boolean

Returns:



7
8
9
# File 'foobara-0.0.110/projects/builtin_types/src/duck/supported_validators/one_of.rb', line 7

def requires_parent_declaration_data?
  true
end

Instance Method Details

#applicable?(value) ⇒ Boolean

Returns:



27
28
29
30
31
# File 'foobara-0.0.110/projects/builtin_types/src/duck/supported_validators/one_of.rb', line 27

def applicable?(value)
  # Might there be some way this validator could be marked not-applicable that doesn't require coupling
  # this processor to allow_nil? (or vice-versa)
  !value.nil? || !parent_declaration_data[:allow_nil]
end

#error_context(value) ⇒ Object



43
44
45
46
47
48
# File 'foobara-0.0.110/projects/builtin_types/src/duck/supported_validators/one_of.rb', line 43

def error_context(value)
  {
    value:,
    valid_values:
  }
end

#error_message(value) ⇒ Object



39
40
41
# File 'foobara-0.0.110/projects/builtin_types/src/duck/supported_validators/one_of.rb', line 39

def error_message(value)
  "#{value} is not one of #{valid_values}"
end

#valid_valuesObject



23
24
25
# File 'foobara-0.0.110/projects/builtin_types/src/duck/supported_validators/one_of.rb', line 23

def valid_values
  declaration_data
end

#validation_errors(value) ⇒ Object



33
34
35
36
37
# File 'foobara-0.0.110/projects/builtin_types/src/duck/supported_validators/one_of.rb', line 33

def validation_errors(value)
  unless valid_values.include?(value)
    build_error(value)
  end
end