Class: MiniDefender::Rules::Filled

Inherits:
MiniDefender::Rule show all
Defined in:
lib/mini_defender/rules/filled.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MiniDefender::Rule

#active?, available?, #bails?, #coerce, #default_value, #defaults?, #error_message, #excluded?, #force_coerce?, #implicit?, make, #priority, #stops?, #with_message

Class Method Details

.signatureObject



4
5
6
# File 'lib/mini_defender/rules/filled.rb', line 4

def self.signature
  'filled'
end

Instance Method Details

#message(attribute, value, validator) ⇒ Object



19
20
21
# File 'lib/mini_defender/rules/filled.rb', line 19

def message(attribute, value, validator)
  'The field should not be empty.'
end

#passes?(attribute, value, validator) ⇒ Boolean

Returns:



8
9
10
11
12
13
14
15
16
17
# File 'lib/mini_defender/rules/filled.rb', line 8

def passes?(attribute, value, validator)
  case value
  when String
    !value.strip.empty?
  when Array, Hash
    !value.empty?
  else
    !value.nil?
  end
end