Class: Datacaster::Trier
- Inherits:
-
Base
- Object
- Base
- Datacaster::Trier
show all
- Defined in:
- lib/datacaster/trier.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, #to_json_schema_attributes, #with_context, #with_object_context, #with_runtime, #|
Constructor Details
#initialize(catched_exception, error_key = nil, &block) ⇒ Trier
3
4
5
6
7
8
9
10
11
|
# File 'lib/datacaster/trier.rb', line 3
def initialize(catched_exception, error_key = nil, &block)
raise "Expected block" unless block_given?
@catched_exception = Array(catched_exception)
@try = block
@error_keys = ['.try', 'datacaster.errors.try']
@error_keys.unshift(error_key) if error_key
end
|
Instance Method Details
#cast(object, runtime:) ⇒ Object
13
14
15
16
17
18
19
|
# File 'lib/datacaster/trier.rb', line 13
def cast(object, runtime:)
begin
Datacaster.ValidResult(Runtimes::Base.(runtime, @try, object))
rescue *@catched_exception
Datacaster.ErrorResult(I18nValues::Key.new(@error_keys, value: object))
end
end
|
#inspect ⇒ Object
21
22
23
|
# File 'lib/datacaster/trier.rb', line 21
def inspect
"#<Datacaster::Trier>"
end
|