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

.configure ⇒ Object

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
# 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(
      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:



26
27
28
# File 'lib/karafka/web/contracts/base.rb', line 26

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