Class: Dry::Validation::Predicate

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/validation/predicate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, *args, &block) ⇒ Predicate

Returns a new instance of Predicate.



15
16
17
18
19
# File 'lib/dry/validation/predicate.rb', line 15

def initialize(id, *args, &block)
  @id = id
  @fn = block
  @args = args
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



13
14
15
# File 'lib/dry/validation/predicate.rb', line 13

def args
  @args
end

#fnObject (readonly)

Returns the value of attribute fn.



13
14
15
# File 'lib/dry/validation/predicate.rb', line 13

def fn
  @fn
end

#idObject (readonly)

Returns the value of attribute id.



13
14
15
# File 'lib/dry/validation/predicate.rb', line 13

def id
  @id
end

Instance Method Details

#call(*args) ⇒ Object



21
22
23
# File 'lib/dry/validation/predicate.rb', line 21

def call(*args)
  fn.(*args)
end

#curry(*args) ⇒ Object



25
26
27
# File 'lib/dry/validation/predicate.rb', line 25

def curry(*args)
  self.class.new(id, *args, &fn.curry.(*args))
end

#to_aryObject Also known as: to_a



29
30
31
# File 'lib/dry/validation/predicate.rb', line 29

def to_ary
  [:predicate, [id, args]]
end