module DirtySeed::Assigners::RegexHelper

Helps with regex validations

Public Instance Methods

regex() click to toggle source

Returns the regex pattern if value should respect a format

For example when: `validates :email, format: { with: /\w{10}@(hotmail|gmail)\.com/ }`

@return [Regex]

# File lib/dirty_seed/assigners/helpers/regex_helper.rb, line 12
def regex
  regex_validator =
    validators&.find do |validator|
      validator.is_a? ActiveModel::Validations::FormatValidator
    end
  regex_validator&.options&.dig(:with)
end
regex_value() click to toggle source

Returns a random value matching the pattern @return [String] @note Rescue from unreadable regex with nil

# File lib/dirty_seed/assigners/helpers/regex_helper.rb, line 23
def regex_value
  regex.random_example
rescue RegexpExamples::IllegalSyntaxError
  nil
end