Class: Bodhi::IsNotEmptyValidator

Inherits:
Validator
  • Object
show all
Defined in:
lib/bodhi-slam/validators/not_empty.rb

Instance Method Summary collapse

Methods inherited from Validator

constantize, #to_sym, #underscore

Constructor Details

#initialize(value) ⇒ IsNotEmptyValidator

Returns a new instance of IsNotEmptyValidator.



4
# File 'lib/bodhi-slam/validators/not_empty.rb', line 4

def initialize(value); end

Instance Method Details

#to_optionsObject



16
17
18
# File 'lib/bodhi-slam/validators/not_empty.rb', line 16

def to_options
  {self.to_sym => true}
end

#validate(record, attribute, value) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/bodhi-slam/validators/not_empty.rb', line 6

def validate(record, attribute, value)
  unless value.nil?

    if value.is_a?(Array)
      record.errors.add(attribute, "must not be empty") if value.empty?
    end

  end
end