Giter Site home page Giter Site logo

not-naughty's Introduction

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

not-naughty's People

Contributors

boof avatar manveru avatar

Stargazers

 avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.