Class: MiniDefender::Rules::RequiredIf
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
#initialize(target, value) ⇒ RequiredIf
Returns a new instance of RequiredIf.
6
7
8
9
10
11
|
# File 'lib/mini_defender/rules/required_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
17
18
19
20
21
|
# File 'lib/mini_defender/rules/required_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
|
.signature ⇒ Object
13
14
15
|
# File 'lib/mini_defender/rules/required_if.rb', line 13
def self.signature
'required_if'
end
|
Instance Method Details
#implicit?(validator) ⇒ Boolean
23
24
25
|
# File 'lib/mini_defender/rules/required_if.rb', line 23
def implicit?(validator)
validator.data.key?(@target) && validator.data[@target] == @value
end
|