module PrelandsRails::AbstractInteractor
Public Instance Methods
call()
click to toggle source
# File lib/prelands_rails/concerns/abstract_interactor.rb, line 11 def call begin act rescue ::Interactor::Failure # bad promises report_error 'Bad promises: %s' % context.errors, context.to_h fail! errors: context.errors rescue ::ActiveRecord::RecordNotFound => e report_error e.message, context.to_h fail! errors: 'not found' rescue StandardError => e error_handler e, context.to_h fail! errors: e.message custom_error_handler e end end
Protected Instance Methods
bad_expects(breaches)
click to toggle source
# File lib/prelands_rails/concerns/abstract_interactor.rb, line 37 def bad_expects(breaches) errors = build_errors_message breaches fail! errors: errors end
build_errors_message(breaches)
click to toggle source
# File lib/prelands_rails/concerns/abstract_interactor.rb, line 43 def build_errors_message(breaches) msgs = breaches.map(&:messages).inspect.scan /(?<=")[^"\]\[{}]+(?=")/ (msgs - [', ']).map { |m| [m,nil] }.to_h.keys.join('; ') end
Private Instance Methods
act()
click to toggle source
# File lib/prelands_rails/concerns/abstract_interactor.rb, line 29 def act raise NotImplementedError, "The `act` method must be defined in #{self.class}" end
custom_error_handler(_e)
click to toggle source
# File lib/prelands_rails/concerns/abstract_interactor.rb, line 33 def custom_error_handler(_e); end