Sha256: 3d39cb19369fd3b6669e87ee772cf890876c6ada9800c130f15600a8a33d8cba

Contents?: true

Size: 768 Bytes

Versions: 3

Compression:

Stored size: 768 Bytes

Contents

module ValidatesFormattingOf
  module ModelAdditions
    def validates_formatting_of(attribute, opts = {})

      # Here is where the input is formatted before it is validated.
      # Not yet implemented.
      # 
      # unless opts[:preformat].nil?
      #   before_validation do
      #     # add formatting changes here
      #   end
      # end

      regex_for_validation = opts[:regex] || validate_with(opts[:using])

      validates_format_of attribute, :with => regex_for_validation, :message => opts[:message]
    end

    def validate_with(method)
      # Actually retrieve the regex to check against
      formatting.send(method)
    end

    def formatting
      # Grab the validating methods
      @formatting ||= ValidatingMethods.new
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
validates_formatting_of-0.2.3 lib/validates_formatting_of/model_additions.rb
validates_formatting_of-0.2.2 lib/validates_formatting_of/model_additions.rb
validates_formatting_of-0.2.1 lib/validates_formatting_of/model_additions.rb