Class: Foobara::Value::Caster
- Inherits:
-
Transformer
- Object
- Processor
- Transformer
- Foobara::Value::Caster
- Defined in:
- foobara-0.0.110/projects/value/src/caster.rb
Overview
TODO: do we really need these?? Can’t just use a transformer?
Direct Known Subclasses
ActiveRecordType::Casters::PrimaryKey, BuiltinTypes::Array::Casters::Arrayable, BuiltinTypes::AssociativeArray::Casters::Array, BuiltinTypes::Attributes::Casters::Hash, BuiltinTypes::BigDecimal::Casters::Integer, BuiltinTypes::BigDecimal::Casters::String, BuiltinTypes::Boolean::Casters::Numeric, BuiltinTypes::Boolean::Casters::StringOrSymbol, BuiltinTypes::Date::Casters::Hash, BuiltinTypes::Date::Casters::String, BuiltinTypes::Datetime::Casters::Date, BuiltinTypes::Datetime::Casters::SecondsSinceEpoch, BuiltinTypes::Datetime::Casters::String, BuiltinTypes::Entity::Casters::PrimaryKey, BuiltinTypes::Float::Casters::Integer, BuiltinTypes::Float::Casters::String, BuiltinTypes::Integer::Casters::String, BuiltinTypes::String::Casters::Numeric, BuiltinTypes::String::Casters::Symbol, BuiltinTypes::Symbol::Casters::String, TypeDeclarations::Caster
Instance Attribute Summary
Attributes inherited from Processor
#created_in_namespace, #declaration_data, #parent_declaration_data
Class Method Summary collapse
- .create(options) ⇒ Object
- .foobara_manifest ⇒ Object
- .requires_declaration_data? ⇒ Boolean
- .subclass(name: nil, **options) ⇒ Object
Instance Method Summary collapse
- #applicable?(_value) ⇒ Boolean
- #applies_message ⇒ Object
- #cast(_value) ⇒ Object
- #transform(value) ⇒ Object
Methods inherited from Transformer
Methods inherited from Processor
#always_applicable?, #attribute_name, #build_error, default_declaration_data, #dup_processor, error_class, error_classes, #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, #process_value!, processor_name, 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
14 15 16 |
# File 'foobara-0.0.110/projects/value/src/caster.rb', line 14 def create() subclass(**).instance end |
.foobara_manifest ⇒ Object
6 7 8 |
# File 'foobara-0.0.110/projects/value/src/caster.rb', line 6 def super.merge(processor_type: :caster) end |
.requires_declaration_data? ⇒ Boolean
10 11 12 |
# File 'foobara-0.0.110/projects/value/src/caster.rb', line 10 def requires_declaration_data? false end |
.subclass(name: nil, **options) ⇒ Object
18 19 20 21 22 23 24 25 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 |
# File 'foobara-0.0.110/projects/value/src/caster.rb', line 18 def subclass(name: nil, **) arity_zero = %i[name applies_message] arity_one = %i[applicable? cast] 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
#applicable?(_value) ⇒ Boolean
61 62 63 64 65 |
# File 'foobara-0.0.110/projects/value/src/caster.rb', line 61 def applicable?(_value) # :nocov: raise "subclass responsibility" # :nocov: end |
#applies_message ⇒ Object
67 68 69 70 71 |
# File 'foobara-0.0.110/projects/value/src/caster.rb', line 67 def # :nocov: raise "subclass responsibility" # :nocov: end |
#cast(_value) ⇒ Object
77 78 79 80 81 |
# File 'foobara-0.0.110/projects/value/src/caster.rb', line 77 def cast(_value) # :nocov: raise "subclass responsibility" # :nocov: end |
#transform(value) ⇒ Object
73 74 75 |
# File 'foobara-0.0.110/projects/value/src/caster.rb', line 73 def transform(value) cast(value) end |