Class: Foobara::Value::Transformer
- Defined in:
- foobara-0.0.110/projects/value/src/transformer.rb
Direct Known Subclasses
BuiltinTypes::Attributes::SupportedTransformers::Defaults, BuiltinTypes::Attributes::Transformers::RemoveUnexpectedAttributes, CommandConnectors::Serializer, CommandConnectors::Transformers::AuthErrorsTransformer, CommandConnectors::Transformers::LoadAggregatesPreCommitTransformer, CommandConnectors::Transformers::LoadDelegatedAttributesEntitiesPreCommitTransformer, TypeDeclarations::Desugarizer, TypeDeclarations::SensitiveTypeRemover, TypeDeclarations::Transformer, TypeDeclarations::TypedTransformer, Caster
Defined Under Namespace
Classes: Runner
Instance Attribute Summary
Attributes inherited from Processor
#created_in_namespace, #declaration_data, #parent_declaration_data
Class Method Summary collapse
- .create(options) ⇒ Object
- .error_classes ⇒ Object
- .foobara_manifest ⇒ Object
-
.subclass(name: nil, **options) ⇒ Object
TODO: make transform the first argument for convenience.
Instance Method Summary collapse
Methods inherited from Processor
#always_applicable?, #applicable?, #attribute_name, #build_error, default_declaration_data, #dup_processor, error_class, #error_context, #error_message, #error_path, #foobara_manifest, #initialize, #inspect, instance, #method_missing, #name, new_with_agnostic_args, #possible_errors, #priority, #process_outcome, #process_outcome!, #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 Concern
foobara_class_methods_module_for, foobara_concern?, included
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
.create(options) ⇒ Object
21 22 23 |
# File 'foobara-0.0.110/projects/value/src/transformer.rb', line 21 def create() subclass(**).instance end |
.error_classes ⇒ Object
17 18 19 |
# File 'foobara-0.0.110/projects/value/src/transformer.rb', line 17 def error_classes [] end |
.foobara_manifest ⇒ Object
13 14 15 |
# File 'foobara-0.0.110/projects/value/src/transformer.rb', line 13 def super.merge(processor_type: :transformer) end |
.subclass(name: nil, **options) ⇒ Object
TODO: make transform the first argument for convenience
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'foobara-0.0.110/projects/value/src/transformer.rb', line 26 def subclass(name: nil, **) arity_zero = %i[always_applicable? priority] arity_one = %i[applicable? transform] allowed = arity_zero + arity_one = .keys - allowed unless .empty? # :nocov: raise ArgumentError, "Invalid options #{} expected only #{allowed}" # :nocov: end name ||= "#{self.name}::Anon#{SecureRandom.hex}" unless name.include?(":") name = "#{self.name}::#{name}" end Util.make_class(name, self) do arity_one.each do |method_name| if .key?(method_name) method = [method_name] define_method method_name do |value| method.call(value) end end end arity_zero.each do |method_name| if .key?(method_name) value = [method_name] define_method method_name do value end end end end end |
Instance Method Details
#process_value(value) ⇒ Object
75 76 77 78 79 80 81 |
# File 'foobara-0.0.110/projects/value/src/transformer.rb', line 75 def process_value(value) if applicable?(value) value = transform(value) end Outcome.success(value) end |
#transform(_value) ⇒ Object
69 70 71 72 73 |
# File 'foobara-0.0.110/projects/value/src/transformer.rb', line 69 def transform(_value) # :nocov: raise "subclass responsibility" # :nocov: end |