Class: Schematic::Generator::Restrictions::Pattern
- Inherits:
-
Base
- Object
- ColumnValidator
- Base
- Schematic::Generator::Restrictions::Pattern
- Defined in:
- lib/schematic/generator/restrictions/pattern.rb
Instance Attribute Summary
Attributes inherited from ColumnValidator
Instance Method Summary collapse
Methods inherited from ColumnValidator
#for_validator, #initialize, #validators_for_column
Constructor Details
This class inherits a constructor from Schematic::Generator::ColumnValidator
Instance Method Details
#generate(builder) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/schematic/generator/restrictions/pattern.rb', line 8 def generate(builder) for_validator ActiveModel::Validations::FormatValidator do |validator| if pattern = validator.[:with] value = pattern.source value.gsub!(/^(?:\^|\\A|\\a)?/, '') value.gsub!(/(?:\$|\\Z|\\z)?$/, '') value.gsub!(/\\\$/, '$') value.gsub!(/\(\?:/, '(') builder.xs(:pattern, 'value' => value) end end end |