Sha256: 7bfa827a3d4fc87f84679d0c0b1f7c995b850ebf267cec3f07a83d87db6ec308

Contents?: true

Size: 549 Bytes

Versions: 4

Compression:

Stored size: 549 Bytes

Contents

# frozen_string_literal: true

module MuchRails; end

# MuchRails::InvalidError allows for raising and auto-rescueing general
# validation errors outside the scope of e.g. an ActiveRecord save.
class MuchRails::InvalidError < StandardError
  attr_reader :errors

  def initialize(backtrace: nil, **errors)
    @errors = errors

    super(@errors.inspect)
    set_backtrace(backtrace) if backtrace
  end

  def error_messages
    @errors.to_a.map do |(field_name, message)|
      "#{field_name}: #{Array.wrap(message).to_sentence}"
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
much-rails-0.4.3 lib/much-rails/invalid_error.rb
much-rails-0.4.2 lib/much-rails/invalid_error.rb
much-rails-0.4.1 lib/much-rails/invalid_error.rb
much-rails-0.4.0 lib/much-rails/invalid_error.rb