Class: Foobara::TypeDeclarations::TypedTransformer
Overview
TODO: this should instead be a processor and have its own possible_errors
Class Attribute Summary collapse
#created_in_namespace, #declaration_data, #parent_declaration_data
Class Method Summary
collapse
Instance Method Summary
collapse
create, error_classes, foobara_manifest, subclass, #transform
#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!, processor_name, #respond_to_missing?, #runner, symbol
#foobara_domain, #foobara_manifest, #foobara_organization, #scoped_clear_caches
Methods included from Concern
foobara_class_methods_module_for, foobara_concern?, included
Constructor Details
#initialize(from: nil, to: nil) ⇒ TypedTransformer
Returns a new instance of TypedTransformer.
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'foobara-0.0.110/projects/type_declarations/src/typed_transformer.rb', line 65
def initialize(from: nil, to: nil)
super()
if from
self.from from
end
if to
self.to to
end
from_type
to_type
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Foobara::Value::Processor
Class Attribute Details
.from_type ⇒ Object
Returns the value of attribute from_type.
22
23
24
|
# File 'foobara-0.0.110/projects/type_declarations/src/typed_transformer.rb', line 22
def from_type
@from_type
end
|
.to_type ⇒ Object
Returns the value of attribute to_type.
22
23
24
|
# File 'foobara-0.0.110/projects/type_declarations/src/typed_transformer.rb', line 22
def to_type
@to_type
end
|
Class Method Details
.from ⇒ Object
14
15
16
|
# File 'foobara-0.0.110/projects/type_declarations/src/typed_transformer.rb', line 14
def from(...)
@from_type = Domain.current.foobara_type_from_declaration(...)
end
|
.requires_declaration_data? ⇒ Boolean
6
7
8
|
# File 'foobara-0.0.110/projects/type_declarations/src/typed_transformer.rb', line 6
def requires_declaration_data?
false
end
|
.requires_parent_declaration_data? ⇒ Boolean
10
11
12
|
# File 'foobara-0.0.110/projects/type_declarations/src/typed_transformer.rb', line 10
def requires_parent_declaration_data?
false
end
|
.to ⇒ Object
18
19
20
|
# File 'foobara-0.0.110/projects/type_declarations/src/typed_transformer.rb', line 18
def to(...)
@to_type = Domain.current.foobara_type_from_declaration(...)
end
|
Instance Method Details
#from ⇒ Object
57
58
59
|
# File 'foobara-0.0.110/projects/type_declarations/src/typed_transformer.rb', line 57
def from(...)
@from_type = Domain.current.foobara_type_from_declaration(...)
end
|
#from_type ⇒ Object
33
34
35
36
37
38
39
|
# File 'foobara-0.0.110/projects/type_declarations/src/typed_transformer.rb', line 33
def from_type
return @from_type if defined?(@from_type)
@from_type = self.class.from_type || if from_type_declaration
Domain.current.foobara_type_from_declaration(from_type_declaration)
end
end
|
#from_type_declaration ⇒ Object
25
26
27
|
# File 'foobara-0.0.110/projects/type_declarations/src/typed_transformer.rb', line 25
def from_type_declaration
nil
end
|
#has_from_type? ⇒ Boolean
53
54
55
|
# File 'foobara-0.0.110/projects/type_declarations/src/typed_transformer.rb', line 53
def has_from_type?
!!from_type
end
|
#has_to_type? ⇒ Boolean
49
50
51
|
# File 'foobara-0.0.110/projects/type_declarations/src/typed_transformer.rb', line 49
def has_to_type?
!!to_type
end
|
#process_value(value) ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'foobara-0.0.110/projects/type_declarations/src/typed_transformer.rb', line 81
def process_value(value)
if has_from_type?
outcome = Namespace.use from_type.created_in_namespace do
from_type.process_value(value)
end
return outcome unless outcome.success?
value = outcome.result
end
output = transform(value)
if has_to_type?
Namespace.use to_type.created_in_namespace do
to_type.process_value(output)
end
else
Outcome.success(output)
end
end
|
#to ⇒ Object
61
62
63
|
# File 'foobara-0.0.110/projects/type_declarations/src/typed_transformer.rb', line 61
def to(...)
@to_type = Domain.current.foobara_type_from_declaration(...)
end
|
#to_type ⇒ Object
41
42
43
44
45
46
47
|
# File 'foobara-0.0.110/projects/type_declarations/src/typed_transformer.rb', line 41
def to_type
return @to_type if defined?(@to_type)
@to_type = self.class.to_type || if to_type_declaration
Domain.current.foobara_type_from_declaration(to_type_declaration)
end
end
|
#to_type_declaration ⇒ Object
29
30
31
|
# File 'foobara-0.0.110/projects/type_declarations/src/typed_transformer.rb', line 29
def to_type_declaration
nil
end
|