Class: Foobara::TypeDeclarations::TypeDeclarationHandler
Instance Attribute Summary collapse
#prioritize
#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
#process_outcome
#error_classes, #possible_errors, #processor_names, #register, requires_declaration_data?
#always_applicable?, #attribute_name, #build_error, default_declaration_data, #dup_processor, error_class, error_classes, #error_context, #error_message, #error_path, #foobara_manifest, 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
#foobara_domain, #foobara_manifest, #foobara_organization, #scoped_clear_caches
Constructor Details
#initialize(*args, processors: nil, desugarizers: starting_desugarizers, type_declaration_validators: starting_type_declaration_validators, **opts) ⇒ TypeDeclarationHandler
Returns a new instance of TypeDeclarationHandler.
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'foobara-0.0.110/projects/type_declarations/src/type_declaration_handler.rb', line 44
def initialize(
*args,
processors: nil,
desugarizers: starting_desugarizers,
type_declaration_validators: starting_type_declaration_validators,
**opts
)
if processors && !processors.empty?
raise ArgumentError, "Cannot set processors directly for a type declaration handler"
end
self.desugarizers = Util.array(desugarizers)
self.type_declaration_validators = Util.array(type_declaration_validators)
super(*Util.args_and_opts_to_args(args, opts))
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Foobara::Value::Processor
Instance Attribute Details
#desugarizers ⇒ Object
Returns the value of attribute desugarizers.
42
43
44
|
# File 'foobara-0.0.110/projects/type_declarations/src/type_declaration_handler.rb', line 42
def desugarizers
@desugarizers
end
|
#type_declaration_validators ⇒ Object
Returns the value of attribute type_declaration_validators.
42
43
44
|
# File 'foobara-0.0.110/projects/type_declarations/src/type_declaration_handler.rb', line 42
def type_declaration_validators
@type_declaration_validators
end
|
Class Method Details
.foobara_manifest ⇒ Object
7
8
9
10
11
|
# File 'foobara-0.0.110/projects/type_declarations/src/type_declaration_handler.rb', line 7
def foobara_manifest
super.merge(processor_type: :type_declaration_handler)
end
|
.starting_desugarizers ⇒ Object
13
14
15
|
# File 'foobara-0.0.110/projects/type_declarations/src/type_declaration_handler.rb', line 13
def starting_desugarizers
starting_desugarizers_with_inherited
end
|
.starting_desugarizers_with_inherited ⇒ Object
17
18
19
20
21
22
23
24
25
|
# File 'foobara-0.0.110/projects/type_declarations/src/type_declaration_handler.rb', line 17
def starting_desugarizers_with_inherited
if superclass == TypeDeclarationHandler
starting_desugarizers_without_inherited
else
[*superclass.starting_desugarizers, *starting_desugarizers_without_inherited]
end
end
|
.starting_desugarizers_without_inherited ⇒ Object
27
28
29
30
31
|
# File 'foobara-0.0.110/projects/type_declarations/src/type_declaration_handler.rb', line 27
def starting_desugarizers_without_inherited
Util.constant_values(self, extends: TypeDeclarations::Desugarizer).map(&:instance)
end
|
.starting_type_declaration_validators ⇒ Object
33
34
35
36
37
|
# File 'foobara-0.0.110/projects/type_declarations/src/type_declaration_handler.rb', line 33
def starting_type_declaration_validators
Util.constant_values(self, extends: Value::Validator, inherit: true).map(&:instance)
end
|
Instance Method Details
#applicable?(_sugary_type_declaration) ⇒ Boolean
85
86
87
88
89
|
# File 'foobara-0.0.110/projects/type_declarations/src/type_declaration_handler.rb', line 85
def applicable?(_sugary_type_declaration)
raise "subclass responsibility"
end
|
#desugarize(value) ⇒ Object
109
110
111
|
# File 'foobara-0.0.110/projects/type_declarations/src/type_declaration_handler.rb', line 109
def desugarize(value)
desugarizer.process_value!(value)
end
|
#desugarizer ⇒ Object
104
105
106
107
|
# File 'foobara-0.0.110/projects/type_declarations/src/type_declaration_handler.rb', line 104
def desugarizer
Value::Processor::Pipeline.new(processors: desugarizers)
end
|
#inspect ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
|
# File 'foobara-0.0.110/projects/type_declarations/src/type_declaration_handler.rb', line 73
def inspect
s = super
if s.size > 400
s = "#{s[0..400]}..."
end
s
end
|
#process_value(raw_type_declaration) ⇒ Object
95
96
97
98
99
100
101
102
|
# File 'foobara-0.0.110/projects/type_declarations/src/type_declaration_handler.rb', line 95
def process_value(raw_type_declaration)
super.tap do |type_outcome|
if type_outcome.success?
type_outcome.result.raw_declaration_data = raw_type_declaration
end
end
end
|
#processors ⇒ Object
91
92
93
|
# File 'foobara-0.0.110/projects/type_declarations/src/type_declaration_handler.rb', line 91
def processors
[desugarizer, type_declaration_validator, to_type_transformer]
end
|
69
70
71
|
# File 'foobara-0.0.110/projects/type_declarations/src/type_declaration_handler.rb', line 69
def to_type_transformer
self.class::ToTypeTransformer.instance
end
|
#type_declaration_validator ⇒ Object
113
114
115
|
# File 'foobara-0.0.110/projects/type_declarations/src/type_declaration_handler.rb', line 113
def type_declaration_validator
Value::Processor::Pipeline.new(processors: type_declaration_validators)
end
|