Class: Attr::Gather::Filters::Contract

Inherits:
Base
  • Object
show all
Defined in:
lib/attr/gather/filters/contract.rb

Overview

Filters values with a dry-validation contract

Defined Under Namespace

Classes: IncompatibleContractError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dry_contract) ⇒ Contract

Creates a new instance of the filter

Parameters:

  • dry_contract (Dry::Contract)


15
16
17
18
19
# File 'lib/attr/gather/filters/contract.rb', line 15

def initialize(dry_contract)
  validate_dry_contract!(dry_contract)
  @dry_contract = dry_contract
  super()
end

Instance Attribute Details

#dry_contractObject (readonly)

Returns the value of attribute dry_contract.



10
11
12
# File 'lib/attr/gather/filters/contract.rb', line 10

def dry_contract
  @dry_contract
end

Instance Method Details

#call(input) ⇒ Object



21
22
23
24
25
# File 'lib/attr/gather/filters/contract.rb', line 21

def call(input)
  value, filterings = filter_validation_errors input.dup

  Result.new(value, filterings)
end