Class: MiniDefender::Rules::DeclinedIf

Inherits:
Declined show all
Defined in:
lib/mini_defender/rules/declined_if.rb

Constant Summary

Constants inherited from Declined

MiniDefender::Rules::Declined::ALLOWED_VALUES

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Declined

#message, #passes?

Methods inherited from MiniDefender::Rule

available?, #bails?, #coerce, #default_value, #defaults?, #error_message, #excluded?, #force_coerce?, #implicit?, #message, #passes?, #priority, #stops?, #with_message

Constructor Details

#initialize(target, value) ⇒ DeclinedIf

Returns a new instance of DeclinedIf.

Raises:

  • (ArgumentError)


6
7
8
9
10
11
# File 'lib/mini_defender/rules/declined_if.rb', line 6

def initialize(target, value)
  raise ArgumentError, 'Target must be a string' unless target.is_a?(String)

  @target = target
  @value = value
end

Class Method Details

.make(args) ⇒ Object

Raises:

  • (ArgumentError)


17
18
19
20
21
# File 'lib/mini_defender/rules/declined_if.rb', line 17

def self.make(args)
  raise ArgumentError, 'Target and expected value are required.' unless args.length == 2

  self.new(args[0], args[1])
end

.signatureObject



13
14
15
# File 'lib/mini_defender/rules/declined_if.rb', line 13

def self.signature
  'declined_if'
end

Instance Method Details

#active?(validator) ⇒ Boolean

Returns:



23
24
25
# File 'lib/mini_defender/rules/declined_if.rb', line 23

def active?(validator)
  validator.data[@target] == @value
end