Class: Karafka::Web::Contracts::Base

Inherits:
Core::Contractable::Contract
  • Object
show all
Defined in:
lib/karafka/web/contracts/base.rb

Overview

Base for all the contracts

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configureObject

This layer is not for users extensive feedback, thus we can easily use the minimum error messaging there is.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/karafka/web/contracts/base.rb', line 12

def configure
  return super if block_given?

  super do |config|
    config.error_messages = YAML.safe_load(
      File.read(
        File.join(Karafka::Web.gem_root, 'config', 'locales', 'errors.yml')
      )
    ).fetch('en').fetch('validations').fetch('web')
  end
end

Instance Method Details

#validate!(data) ⇒ Boolean

Returns true if all good.

Parameters:

  • data (Hash)

    data for validation

Returns:

  • (Boolean)

    true if all good

Raises:



28
29
30
# File 'lib/karafka/web/contracts/base.rb', line 28

def validate!(data)
  super(data, Errors::ContractError)
end