Sha256: 9add4475487f8db1aebf2e8a3b2acbf3444adbb14680d7ed48416854841b1ad9

Contents?: true

Size: 587 Bytes

Versions: 5

Compression:

Stored size: 587 Bytes

Contents

module BloodContracts::Core
  # Custom refinement type that converts the extracted data into
  # Tram::Policy::Errors, could by used when the case is an error but
  # you know how to deal with it inside application
  class ExpectedError < Ext::Refined
    # Generates an Tram::Policy::Errors message using the matching context
    #
    # @return [Tram::Policy::Errors]
    def mapped
      keys = self.class.extractors.keys
      tags = Hash[keys.zip(@context.values_at(*keys))]
      tags = @context if tags.empty?
      self.class.define_error(:message, tags: tags)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
blood_contracts-ext-0.1.4 lib/blood_contracts/core/expected_error.rb
blood_contracts-ext-0.1.3 lib/blood_contracts/core/expected_error.rb
blood_contracts-ext-0.1.2 lib/blood_contracts/core/expected_error.rb
blood_contracts-ext-0.1.1 lib/blood_contracts/core/expected_error.rb
blood_contracts-ext-0.1.0 lib/blood_contracts/core/expected_error.rb