Class: MiniDefender::Rules::Required

Inherits:
MiniDefender::Rule show all
Defined in:
lib/mini_defender/rules/required.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?, make, #priority, #stops?, #with_message

Class Method Details

.signatureObject



6
7
8
# File 'lib/mini_defender/rules/required.rb', line 6

def self.signature
  'required'
end

Instance Method Details

#implicit?(validator) ⇒ Boolean

Returns:



10
11
12
# File 'lib/mini_defender/rules/required.rb', line 10

def implicit?(validator)
  true
end

#message(attribute, value, validator) ⇒ Object



29
30
31
# File 'lib/mini_defender/rules/required.rb', line 29

def message(attribute, value, validator)
  "This field is required."
end

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

Returns:



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/mini_defender/rules/required.rb', line 14

def passes?(attribute, value, validator)
  case value
  when nil
    false
  when String
    value.strip.length > 0
  when Enumerable
    value.length > 0
  when ActionDispatch::Http::UploadedFile
    value.path && value.path.length > 0 && value.size > 0
  else
    true
  end
end