Class: Saviour::Validator::AttachmentValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/saviour/validator.rb

Instance Method Summary collapse

Constructor Details

#initialize(model, column, validations) ⇒ AttachmentValidator

Returns a new instance of AttachmentValidator.



5
6
7
8
9
10
# File 'lib/saviour/validator.rb', line 5

def initialize(model, column, validations)
  @model = model
  @column = column
  @validations = validations
  @file = model.send(column)
end

Instance Method Details

#validate!Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/saviour/validator.rb', line 12

def validate!
  @validations.each do |data|
    type = data[:type]
    method_or_block = data[:method_or_block]

    case type
    when :memory
      run_validation(method_or_block)
    when :file
      run_validation_as_file(method_or_block)
    end
  end

ensure
  @source_as_file.close! if @source_as_file
end