Module: ExceptionTransformer::ClassMethods
- Defined in:
- lib/exception_transformer.rb
Instance Method Summary collapse
- #find_exception_transformer(group) ⇒ Object
- #find_or_create_exception_transformer(group, strategy) ⇒ Object
-
#transform_exceptions(*exceptions, group: :default, to: nil, where: nil, with: nil, validate: nil) ⇒ Object
Add exceptions to be transformed in ‘handle_exceptions` block.
Instance Method Details
#find_exception_transformer(group) ⇒ Object
68 69 70 |
# File 'lib/exception_transformer.rb', line 68 def find_exception_transformer(group) exception_transformers[group] end |
#find_or_create_exception_transformer(group, strategy) ⇒ Object
72 73 74 |
# File 'lib/exception_transformer.rb', line 72 def find_or_create_exception_transformer(group, strategy) exception_transformers[group] ||= Transformer.new(strategy) end |
#transform_exceptions(*exceptions, group: :default, to: nil, where: nil, with: nil, validate: nil) ⇒ Object
Add exceptions to be transformed in ‘handle_exceptions` block.
58 59 60 61 62 63 64 65 66 |
# File 'lib/exception_transformer.rb', line 58 def transform_exceptions(*exceptions, group: :default, to: nil, where: nil, with: nil, validate: nil) strategies = { validate: validate, delegate: with, rewrite: to, regex: where } strategy = strategies.keys.find { |s| strategies[s].present? } target = strategies[strategy] transformer = find_or_create_exception_transformer(group, strategy) transformer.register_target(target, exceptions) end |