Class: Attestor::Validations::Validators Private

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/attestor/validations/validators.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

The collection of validations used by class instances

Class Method Summary collapse

Class Method Details

.add(name, options = {}) ⇒ Attestor::Validators

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns validators updated by new item

Parameters:

  • name (#to_sym)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :except (Array<#to_sym>)
  • :only (Array<#to_sym>)
  • :policy (Symbol, nil)

Returns:

  • (Attestor::Validators)


47
48
49
50
51
52
# File 'lib/attestor/validations/validators.rb', line 47

def add(name, options = {})
  item = Validator.new(name, options)
  return self if include? item

  self.class.new(@items + [item])
end

.each {|item| ... } ⇒ Enumerator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Iterates through the collection

Yields:

  • the block

Yield Parameters:

  • item (Attestor::Validators::Validator)

    items from the collection

Returns:

  • (Enumerator)


34
35
36
# File 'lib/attestor/validations/validators.rb', line 34

def each
  block_given? ? @items.each { |item| yield(item) } : to_enum
end

.initialize(items = []) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



22
23
24
25
# File 'lib/attestor/validations/validators.rb', line 22

def initialize(items = [])
  @items = items
  freeze
end

.new(items = []) ⇒ Attestor::Validators

Creates an immutable collection with optional list of items

Parameters:

  • items (Array<Attestor::Validators::Validator>) (defaults to: [])

Returns:

  • (Attestor::Validators)


# File 'lib/attestor/validations/validators.rb', line 13

.set(context) ⇒ Attestor::Validators

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns validators used in given context

Parameters:

  • context (#to_sym)

Returns:

  • (Attestor::Validators)


59
60
61
62
63
# File 'lib/attestor/validations/validators.rb', line 59

def set(context)
  validators = select { |item| item.used_in_context? context }

  self.class.new(validators)
end