Class: MiniDefender::Rules::ExcludedWithout

Inherits:
MiniDefender::Rule show all
Defined in:
lib/mini_defender/rules/excluded_without.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) ⇒ ExcludedWithout

Returns a new instance of ExcludedWithout.

Raises:

  • (ArgumentError)


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

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

  @target = target
end

Class Method Details

.make(args) ⇒ Object

Raises:

  • (ArgumentError)


14
15
16
17
18
# File 'lib/mini_defender/rules/excluded_without.rb', line 14

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

  self.new(args[0])
end

.signatureObject



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

def self.signature
  'excluded_without'
end

Instance Method Details

#excluded?(validator) ⇒ Boolean

Returns:



20
21
22
# File 'lib/mini_defender/rules/excluded_without.rb', line 20

def excluded?(validator)
  !validator.data.key?(@target)
end

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

Returns:



24
25
26
# File 'lib/mini_defender/rules/excluded_without.rb', line 24

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