Class: MiniDefender::Rules::Accepted

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

Direct Known Subclasses

AcceptedIf

Constant Summary collapse

ALLOWED_VALUES =
['yes', 'on', 1, true]

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



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

def self.signature
  'accepted'
end

Instance Method Details

#message(attribute, value, validator) ⇒ Object



14
15
16
# File 'lib/mini_defender/rules/accepted.rb', line 14

def message(attribute, value, validator)
  "Must be accepted."
end

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

Returns:



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

def passes?(attribute, value, validator)
  !value.nil? && ALLOWED_VALUES.include?(value)
end