Class: MiniDefender::Rules::ProhibitedIf
Class Method Summary
collapse
Instance Method Summary
collapse
available?, #bails?, #coerce, #default_value, #defaults?, #error_message, #excluded?, #force_coerce?, #implicit?, #priority, #stops?, #with_message
Constructor Details
#initialize(target, value) ⇒ ProhibitedIf
Returns a new instance of ProhibitedIf.
4
5
6
7
8
9
|
# File 'lib/mini_defender/rules/prohibited_if.rb', line 4
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
15
16
17
18
19
|
# File 'lib/mini_defender/rules/prohibited_if.rb', line 15
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
11
12
13
|
# File 'lib/mini_defender/rules/prohibited_if.rb', line 11
def self.signature
'prohibited_if'
end
|
Instance Method Details
#active?(validator) ⇒ Boolean
21
22
23
|
# File 'lib/mini_defender/rules/prohibited_if.rb', line 21
def active?(validator)
validator.data.key?(@target) && validator.data[@target] == @value
end
|
#message(attribute, value, validator) ⇒ Object
29
30
31
|
# File 'lib/mini_defender/rules/prohibited_if.rb', line 29
def message(attribute, value, validator)
"This field is prohibited."
end
|
#passes?(attribute, value, validator) ⇒ Boolean
25
26
27
|
# File 'lib/mini_defender/rules/prohibited_if.rb', line 25
def passes?(attribute, value, validator)
value.blank?
end
|