module Shrine::Plugins::Validation::AttacherMethods

  1. lib/shrine/plugins/validation.rb

Methods

Public Class

  1. new

Public Instance

  1. attach
  2. attach_cached
  3. errors
  4. validate

Attributes

errors [R]

Returns an array of validation errors created on file assignment in the Attacher.validate block.

Public Class methods

new(**options)

Initializes validation errors to an empty array.

[show source]
   # File lib/shrine/plugins/validation.rb
27 def initialize(**options)
28   super
29   @errors = []
30 end

Public Instance methods

attach(io, validate: nil, **options)

Performs validations after attaching file.

[show source]
   # File lib/shrine/plugins/validation.rb
40 def attach(io, validate: nil, **options)
41   result = super(io, **options)
42   validation(validate)
43   result
44 end
attach_cached(value, validate: nil, **options)

Performs validations after attaching cached file.

[show source]
   # File lib/shrine/plugins/validation.rb
33 def attach_cached(value, validate: nil, **options)
34   result = super(value, validate: false, **options)
35   validation(validate)
36   result
37 end
validate(**options)

Runs the validation defined by Attacher.validate.

[show source]
   # File lib/shrine/plugins/validation.rb
47 def validate(**options)
48   errors.clear
49   _validate(**options) if attached?
50 end