Class: MiniDefender::Rules::RequiredWith
- Inherits:
-
Required
show all
- Defined in:
- lib/mini_defender/rules/required_with.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Required
#message, #passes?
#active?, available?, #bails?, #coerce, #default_value, #defaults?, #error_message, #excluded?, #force_coerce?, #message, #passes?, #priority, #stops?, #with_message
Constructor Details
Returns a new instance of RequiredWith.
6
7
8
9
10
11
12
|
# File 'lib/mini_defender/rules/required_with.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
18
19
20
21
22
|
# File 'lib/mini_defender/rules/required_with.rb', line 18
def self.make(args)
raise ArgumentError, 'Expected at least one argument.' unless args.length >= 1
self.new(args)
end
|
.signature ⇒ Object
14
15
16
|
# File 'lib/mini_defender/rules/required_with.rb', line 14
def self.signature
'required_with'
end
|
Instance Method Details
#implicit?(validator) ⇒ Boolean
24
25
26
|
# File 'lib/mini_defender/rules/required_with.rb', line 24
def implicit?(validator)
@targets.any? { |t| validator.data.key?(t) }
end
|