Class: MatchesRegex
- Defined in:
- lib/bureaucrat/validation_old.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(regex, custom_error_code = nil) ⇒ MatchesRegex
constructor
A new instance of MatchesRegex.
- #validate(value, all_values = {}, object = nil) ⇒ Object
Methods inherited from Validator
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 |