Class: MiniDefender::Rules::RequiredWithAll

Inherits:
Required show all
Defined in:
lib/mini_defender/rules/required_with_all.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Required

#message, #passes?

Methods inherited from MiniDefender::Rule

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

Constructor Details

#initialize(targets) ⇒ RequiredWithAll

Returns a new instance of RequiredWithAll.



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

def initialize(targets)
  unless targets.is_a?(Array) && targets.all?{ |t| t.is_a?(String) }
    raise ArgumentError, 'Expected an array of strings.'
  end

  @targets = targets
end

Class Method Details

.make(args) ⇒ Object

Raises:

  • (ArgumentError)


18
19
20
21
22
# File 'lib/mini_defender/rules/required_with_all.rb', line 18

def self.make(args)
  raise ArgumentError, 'Expected at least one argument.' unless args.length >= 1

  self.new(args)
end

.signatureObject



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

def self.signature
  'required_with_all'
end

Instance Method Details

#implicit?(validator) ⇒ Boolean

Returns:



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

def implicit?(validator)
  @targets.all? { |t| validator.data.key?(t) }
end