Class: MiniDefender::Rules::NotRegex
Class Method Summary
collapse
Instance Method Summary
collapse
#active?, available?, #bails?, #coerce, #default_value, #defaults?, #error_message, #excluded?, #force_coerce?, #implicit?, #priority, #stops?, #with_message
Constructor Details
#initialize(pattern) ⇒ NotRegex
Returns a new instance of NotRegex.
4
5
6
7
8
|
# File 'lib/mini_defender/rules/not_regex.rb', line 4
def initialize(pattern)
raise ArgumentError, 'Expected a Regexp instance.' unless pattern.is_a?(Regexp)
@pattern = pattern
end
|
Class Method Details
.make(args) ⇒ Object
14
15
16
17
18
|
# File 'lib/mini_defender/rules/not_regex.rb', line 14
def self.make(args)
raise ArgumentError, 'Expected a pattern as input.' unless args.length > 0
new(Regexp.compile(args.join(',')))
end
|
.signature ⇒ Object
10
11
12
|
# File 'lib/mini_defender/rules/not_regex.rb', line 10
def self.signature
'not_regex'
end
|
Instance Method Details
#message(attribute, value, validator) ⇒ Object
24
25
26
|
# File 'lib/mini_defender/rules/not_regex.rb', line 24
def message(attribute, value, validator)
"The value must not match #{@pattern.to_s}."
end
|
#passes?(attribute, value, validator) ⇒ Boolean
20
21
22
|
# File 'lib/mini_defender/rules/not_regex.rb', line 20
def passes?(attribute, value, validator)
!value.to_s.match?(@pattern)
end
|