Class: Datacaster::Transformer
- Inherits:
-
Base
- Object
- Base
- Datacaster::Transformer
show all
- Defined in:
- lib/datacaster/transformer.rb
Instance Method Summary
collapse
Methods included from Mixin
#&, #*, #call, #call_with_runtime, #cast_errors, #i18n_key, #i18n_map_keys, #i18n_scope, #i18n_vars, #json_schema, #json_schema_attributes, #then, #to_json_schema, #with_context, #with_object_context, #with_runtime, #|
Constructor Details
Returns a new instance of Transformer.
3
4
5
6
7
|
# File 'lib/datacaster/transformer.rb', line 3
def initialize(&block)
raise "Expected block" unless block_given?
@transform = block
end
|
Instance Method Details
#cast(object, runtime:) ⇒ Object
9
10
11
12
13
14
15
|
# File 'lib/datacaster/transformer.rb', line 9
def cast(object, runtime:)
result = Runtimes::Base.(runtime, @transform, object)
if runtime.respond_to?(:will_not_check!)
runtime.will_not_check!
end
Datacaster::ValidResult(result)
end
|
#inspect ⇒ Object
21
22
23
|
# File 'lib/datacaster/transformer.rb', line 21
def inspect
"#<Datacaster::Transformer>"
end
|
#to_json_schema_attributes ⇒ Object
17
18
19
|
# File 'lib/datacaster/transformer.rb', line 17
def to_json_schema_attributes
super.merge(required: false)
end
|