Skip to content
Validation Framework for Ruby.
Ruby
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
spec
.gitignore
CHANGELOG.rdoc
COPYING
README.rdoc
Rakefile
not-naughty.gemspec

README.rdoc

NotNaughty - The Validation Framework

NotNaughty extends your ruby Project with a highly custumizable validation API.

Features

Easy to adapt:

require 'rubygems'
require 'not_naughty'

Person = Struct.new(:name) do
  extend NotNaughty
  validates(:name) { presence and length :minimum => 4 }
end

Person.new('Horst').valid? # => true
Person.new('Foo').valid? # => false

Easy to extent:

class ExampleValidation < NotNaughty::Validation
  def initialize(options, attributes)
    msg = options[:message] || '#{"%s".humanize} is not an example.'

    super options, attributes do |record, attribute, value|
      record.errors.add(attribute, msg) unless value.is_a? Example
    end
  end
end

Person.instance_eval do
  validates_example_of :example_attribute
end

Handle SQL error gracefully:

Person.instance_eval do
  validator.error_handler.handle(SQLError) { |err| '...' }
end

Syntactical Sugar with Builder methods:

validates(:username, :password, :if => :new?) {length :minimum => 6}
validates(:password, :allow_blank => 1) {confirmation and complexity :high}

Beautiful error messages:

validates_presence_of :red_shoes,
  :message => '#{"%s".humanize} are not here.' # => Red shoes are not here.

Conditional Validations:

validates(:if => :necessary?) {...}
validates(:unless => proc {|obj| obj.vip?}) { '...' }

Copying

:include: COPYING

You can’t perform that action at this time.