Class: Foobara::TypeDeclarations::TypedTransformer
- Inherits:
-
Value::Transformer
show all
- Defined in:
- foobara-0.5.8/projects/typesystem/projects/type_declarations/src/typed_transformer.rb
Overview
TODO: this should instead be a processor and have its own possible_errors TODO: does it make sense that this is in this project? Seems to be more generic than TypeDeclarations
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, #transform
#applicable?, #attribute_name, #build_error, default_declaration_data, #dup_processor, error_class, #error_class, error_classes, #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, #requires_declaration_data?, #requires_parent_declaration_data?, #respond_to_missing?, #runner, symbol, #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.
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'projects/typesystem/projects/type_declarations/src/typed_transformer.rb', line 87
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.
40
41
42
|
# File 'projects/typesystem/projects/type_declarations/src/typed_transformer.rb', line 40
def from_type
@from_type
end
|
.to_type ⇒ Object
Returns the value of attribute to_type.
40
41
42
|
# File 'projects/typesystem/projects/type_declarations/src/typed_transformer.rb', line 40
def to_type
@to_type
end
|
Class Method Details
.from ⇒ Object
32
33
34
|
# File 'projects/typesystem/projects/type_declarations/src/typed_transformer.rb', line 32
def from(...)
@from_type = Domain.current.foobara_type_from_declaration(...)
end
|
.requires_declaration_data? ⇒ Boolean
24
25
26
|
# File 'projects/typesystem/projects/type_declarations/src/typed_transformer.rb', line 24
def requires_declaration_data?
false
end
|
.requires_parent_declaration_data? ⇒ Boolean
28
29
30
|
# File 'projects/typesystem/projects/type_declarations/src/typed_transformer.rb', line 28
def requires_parent_declaration_data?
false
end
|
.subclass(to: nil, from: nil, &map_proc) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'projects/typesystem/projects/type_declarations/src/typed_transformer.rb', line 7
def subclass(to: nil, from: nil, &map_proc)
klass = Class.new(self)
klass.to(to) if to
klass.from(from) if from
if map_proc
if map_proc.arity.zero?
klass.define_method(:transform) { |_ignored| map_proc.call }
else
klass.define_method(:transform, &map_proc)
end
end
klass
end
|
.to ⇒ Object
36
37
38
|
# File 'projects/typesystem/projects/type_declarations/src/typed_transformer.rb', line 36
def to(...)
@to_type = Domain.current.foobara_type_from_declaration(...)
end
|
Instance Method Details
#always_applicable? ⇒ Boolean
43
44
45
|
# File 'projects/typesystem/projects/type_declarations/src/typed_transformer.rb', line 43
def always_applicable?
true
end
|
#from ⇒ Object
79
80
81
|
# File 'projects/typesystem/projects/type_declarations/src/typed_transformer.rb', line 79
def from(...)
@from_type = Domain.current.foobara_type_from_declaration(...)
end
|
#from_type ⇒ Object
55
56
57
58
59
60
61
|
# File 'projects/typesystem/projects/type_declarations/src/typed_transformer.rb', line 55
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
47
48
49
|
# File 'projects/typesystem/projects/type_declarations/src/typed_transformer.rb', line 47
def from_type_declaration
nil
end
|
#has_from_type? ⇒ Boolean
75
76
77
|
# File 'projects/typesystem/projects/type_declarations/src/typed_transformer.rb', line 75
def has_from_type?
!!from_type
end
|
#has_to_type? ⇒ Boolean
71
72
73
|
# File 'projects/typesystem/projects/type_declarations/src/typed_transformer.rb', line 71
def has_to_type?
!!to_type
end
|
#process_value(value) ⇒ Object
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'projects/typesystem/projects/type_declarations/src/typed_transformer.rb', line 103
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
83
84
85
|
# File 'projects/typesystem/projects/type_declarations/src/typed_transformer.rb', line 83
def to(...)
@to_type = Domain.current.foobara_type_from_declaration(...)
end
|
#to_type ⇒ Object
63
64
65
66
67
68
69
|
# File 'projects/typesystem/projects/type_declarations/src/typed_transformer.rb', line 63
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
51
52
53
|
# File 'projects/typesystem/projects/type_declarations/src/typed_transformer.rb', line 51
def to_type_declaration
nil
end
|