Sha256: 187998d0e581f08dd6c28fc6fa42e7b079e2aaef153b7d793c30bca959ce6311

Contents?: true

Size: 589 Bytes

Versions: 26

Compression:

Stored size: 589 Bytes

Contents

module Schematic
  module Generator
    module Restrictions
      class Pattern < Base
        def generate(builder)
          for_validator ActiveModel::Validations::FormatValidator do |validator|
            if pattern = validator.options[:with]
              value = pattern.source
              value.gsub!(/^(?:\^|\\A|\\a)?/, '')
              value.gsub!(/(?:\$|\\Z|\\z)?$/, '')
              value.gsub!(/\\\$/, '$')
              value.gsub!(/\(\?:/, '(')
              builder.xs(:pattern, "value" => value)
            end
          end
        end
      end
    end
  end
end


Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
schematic-0.3.6 lib/schematic/generator/restrictions/pattern.rb
schematic-0.3.5 lib/schematic/generator/restrictions/pattern.rb
schematic-0.3.4 lib/schematic/generator/restrictions/pattern.rb
schematic-0.3.3 lib/schematic/generator/restrictions/pattern.rb
schematic-0.3.2 lib/schematic/generator/restrictions/pattern.rb
schematic-0.3.1 lib/schematic/generator/restrictions/pattern.rb