Class: MiniDefender::Rules::LessThan

Inherits:
Size show all
Defined in:
lib/mini_defender/rules/less_than.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Size

#initialize, make

Methods inherited from MiniDefender::Rule

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

Constructor Details

This class inherits a constructor from MiniDefender::Rules::Size

Class Method Details

.signatureObject



7
8
9
# File 'lib/mini_defender/rules/less_than.rb', line 7

def self.signature
  'lt'
end

Instance Method Details

#message(attribute, value, validator) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/mini_defender/rules/less_than.rb', line 24

def message(attribute, value, validator)
  case value
  when ActionDispatch::Http::UploadedFile
    "The file size must be less than #{@size} bytes."
  when Numeric
    "The value must be less than #{@size}."
  else
    "The value length must be less than #{@size}."
  end
end

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

Returns:



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/mini_defender/rules/less_than.rb', line 11

def passes?(attribute, value, validator)
  case value
  when String, Array, Hash
    value.length < @size
  when ActionDispatch::Http::UploadedFile
    value.size < @size
  when Numeric
    value < @size
  else
    false
  end
end