Module: Shrine::Plugins::Validation::AttacherMethods
- Defined in:
- lib/shrine/plugins/validation.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns an array of validation errors created on file assignment in the ‘Attacher.validate` block.
Instance Method Summary collapse
-
#attach(io, validate: nil) ⇒ Object
Performs validations after attaching file.
-
#attach_cached(value, validate: nil) ⇒ Object
Performs validations after attaching cached file.
-
#initialize ⇒ Object
Initializes validation errors to an empty array.
-
#validate(**options) ⇒ Object
Runs the validation defined by ‘Attacher.validate`.
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns an array of validation errors created on file assignment in the ‘Attacher.validate` block.
24 25 26 |
# File 'lib/shrine/plugins/validation.rb', line 24 def errors @errors end |
Instance Method Details
#attach(io, validate: nil) ⇒ Object
Performs validations after attaching file.
40 41 42 43 44 |
# File 'lib/shrine/plugins/validation.rb', line 40 def attach(io, validate: nil, **) result = super(io, **) validation(validate) result end |
#attach_cached(value, validate: nil) ⇒ Object
Performs validations after attaching cached file.
33 34 35 36 37 |
# File 'lib/shrine/plugins/validation.rb', line 33 def attach_cached(value, validate: nil, **) result = super(value, validate: false, **) validation(validate) result end |
#initialize ⇒ Object
Initializes validation errors to an empty array.
27 28 29 30 |
# File 'lib/shrine/plugins/validation.rb', line 27 def initialize(**) super @errors = [] end |
#validate(**options) ⇒ Object
Runs the validation defined by ‘Attacher.validate`.
47 48 49 50 |
# File 'lib/shrine/plugins/validation.rb', line 47 def validate(**) errors.clear _validate(**) if attached? end |