Class: MiniDefender::Rules::RequiredUnless
- Inherits:
-
Required
show all
- Defined in:
- lib/mini_defender/rules/required_unless.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
#initialize(target, value) ⇒ RequiredUnless
Returns a new instance of RequiredUnless.
6
7
8
9
10
11
|
# File 'lib/mini_defender/rules/required_unless.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_unless.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_unless.rb', line 13
def self.signature
'required_unless'
end
|
Instance Method Details
#implicit?(validator) ⇒ Boolean
23
24
25
|
# File 'lib/mini_defender/rules/required_unless.rb', line 23
def implicit?(validator)
validator.data.key?(@target) && validator.data[@target] != @value
end
|