GithubHelp home page GithubHelp logo

vanguard's Introduction

vanguard

This library provides external validations for any Ruby class.

History:

It originates from emmanuels aequitas repository with the following changes:

  • Only support for external validators
  • Use composable algebra for internals
  • Will allow serialization to javascript for client side validation (not implemented)
  • No contextual validators anymore (use additional external validators)
  • 100% code rewrite
  • Use equalizer and adamantium where possible.

Specifying Validations

require 'vanguard'

class ProgrammingLanguage
  attr_reader :name

  def initialize(name)
    @name = name
  end
end

VALIDATOR = Vanguard::Validator.build do
  validates_presence_of :name
end

ruby = ProgrammingLanguage.new('ruby')

result = VALIDATOR.call(ruby)
result.valid? # => true
result.violations # => #<Set: {}>

other = ProgrammingLanguage.new('')

result = VALIDATOR.call(other)
result.valid? # => false
result.violations # => #<Set: {<Vanguard:::Violation ....>}>

See Vanguard::Macros to learn about the complete collection of validation rules available.

Credits

Working with Validation Errors

If an instance fails one or more validation rules, Vanguard::Violation instances will populate the Vanguard::ViolationSet object that is available through the Vanguard::Result#violations method.

Vanguard currently has no support for generating human readable violation messages!

For example:

result = YOUR_VALIDATOR.call(Account.new(:name => "Jose"))
if result.valid?
  # my_account is valid and can be saved
else
  result.violations.each do |e|
    do_something_with(e)
  end
end

##Contextual Validation

Vanguard does not provide a means of grouping your validations into contexts. Define a validator per context for this.

vanguard's People

Contributors

mbj avatar snusnu avatar ptico avatar

Watchers

Joshva 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.