Class: MatchesRegex

Inherits:
Validator show all
Defined in:
lib/bureaucrat/validation_old.rb

Direct Known Subclasses

IsEmail

Instance Method Summary collapse

Methods inherited from Validator

#blank?, #valid?

Constructor Details

#initialize(regex, custom_error_code = nil) ⇒ MatchesRegex

Returns a new instance of MatchesRegex.



131
132
133
134
# File 'lib/bureaucrat/validation_old.rb', line 131

def initialize(regex, custom_error_code=nil)
  @regex = regex
  @custom_error_code = custom_error_code
end

Instance Method Details

#validate(value, all_values = {}, object = nil) ⇒ Object



136
137
138
139
# File 'lib/bureaucrat/validation_old.rb', line 136

def validate(value, all_values={}, object=nil)
  fail_with(@custom_error_code || :not_matching_regex,
            :regex => @regex) if @regex !~ value
end