Class: Apipie::Validator::RegexpValidator

Inherits:
BaseValidator show all
Defined in:
lib/apipie/validator.rb

Overview

validate arguments value with regular expression

Instance Attribute Summary

Attributes inherited from BaseValidator

#param_description

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseValidator

#==, #error, #expected_type, find, #format_description_value, #ignore_allow_blank?, inherited, #inspect, #inspected_fields, #merge_with, #param_name, #params_ordered, raise_if_missing_params, #to_json, #to_s, #valid?

Constructor Details

#initialize(param_description, argument) ⇒ RegexpValidator

Returns a new instance of RegexpValidator.



158
159
160
161
# File 'lib/apipie/validator.rb', line 158

def initialize(param_description, argument)
  super(param_description)
  @regexp = argument
end

Class Method Details

.build(param_description, argument, options, proc) ⇒ Object



167
168
169
# File 'lib/apipie/validator.rb', line 167

def self.build(param_description, argument, options, proc)
  self.new(param_description, argument) if argument.is_a? Regexp
end

Instance Method Details

#descriptionObject



171
172
173
# File 'lib/apipie/validator.rb', line 171

def description
  "Must match regular expression #{format_description_value("/#{@regexp.source}/")}."
end

#validate(value) ⇒ Object



163
164
165
# File 'lib/apipie/validator.rb', line 163

def validate(value)
  value =~ @regexp
end