Class: MiniDefender::Rules::ExcludedUnless

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MiniDefender::Rule

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

Constructor Details

#initialize(target, value) ⇒ ExcludedUnless

Returns a new instance of ExcludedUnless.

Raises:

  • (ArgumentError)


4
5
6
7
8
9
# File 'lib/mini_defender/rules/excluded_unless.rb', line 4

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)


15
16
17
18
19
# File 'lib/mini_defender/rules/excluded_unless.rb', line 15

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

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

.signatureObject



11
12
13
# File 'lib/mini_defender/rules/excluded_unless.rb', line 11

def self.signature
  'excluded_unless'
end

Instance Method Details

#excluded?(validator) ⇒ Boolean

Returns:



21
22
23
# File 'lib/mini_defender/rules/excluded_unless.rb', line 21

def excluded?(validator)
  ! (validator.data.key?(@target) && validator.data[@target] == @value)
end

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

Returns:



25
26
27
# File 'lib/mini_defender/rules/excluded_unless.rb', line 25

def passes?(attribute, value, validator)
  true
end