Class: Datacaster::Transformer
- Defined in:
- lib/datacaster/transformer.rb
Instance Method Summary collapse
- #cast(object, runtime:) ⇒ Object
-
#initialize(&block) ⇒ Transformer
constructor
A new instance of Transformer.
- #inspect ⇒ Object
Methods included from Mixin
#&, #*, #call, #call_with_runtime, #cast_errors, #i18n_key, #i18n_map_keys, #i18n_scope, #i18n_vars, #then, #with_context, #with_object_context, #with_runtime, #|
Constructor Details
#initialize(&block) ⇒ Transformer
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
17 18 19 |
# File 'lib/datacaster/transformer.rb', line 17 def inspect "#<Datacaster::Transformer>" end |