• Stars
    star
    120
  • Rank 294,826 (Top 6 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 11 years ago
  • Updated over 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

External validations for ruby objects

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.

More Repositories

1

mutant

Automated code reviews via mutation testing - semantic code coverage.
Ruby
1,947
star
2

unparser

Turn Ruby AST into semantically equivalent Ruby source
Ruby
309
star
3

anima

Object initializer from attributes hash
Ruby
173
star
4

stratosphere

Haskell EDSL and type-checker for AWS CloudFormation templates
Haskell
162
star
5

concord

Mixin to ease compositions in ruby
Ruby
112
star
6

devtools

The rake ci task!
Ruby
64
star
7

inflecto

Inflector for ruby
46
star
8

auom

Algebra with units of measurement.
Ruby
27
star
9

axiom-mongo-adapter

An MongoDB adapter for Axiom
Ruby
11
star
10

esearch

A ruby driver for elasticsearch that is ONLY A DRIVER.
Ruby
11
star
11

axiom-arango-adapter

An ArangoDB adapter for Axiom
Ruby
8
star
12

mhs

Haskell tooling megarepo
Haskell
8
star
13

axiom-elasticsearch-adapter

An Elasticsearch adapter for Axiom.
Ruby
8
star
14

mprelude-rb

Ruby
7
star
15

to_source

Generator for equivalent source from rubinius AST
Ruby
7
star
16

aql

The ArangoDB AQL AST and to_source implementation
Ruby
7
star
17

ruby-cdb

Ruby cdb reader and writer
C
6
star
18

guard-mutant

Mutant integration for guard
Ruby
6
star
19

mapper

A simple mapper without a latin name. (abandoned)
Ruby
6
star
20

axiom-fuzzer

A fuzzer for axiom relations
Ruby
6
star
21

assets

Playground for a nicer asset system
Ruby
6
star
22

response

Build HTTP responses
Ruby
5
star
23

request

Abstract not only the rack env in something more nice
Ruby
5
star
24

pgt

SQL Golden Testing Tool for postgresql
Haskell
5
star
25

ffprobe

Ruby wrapper around ffprobe
Ruby
4
star
26

eventstorm

unfinished zmq based event aggregation framework
Ruby
4
star
27

tasty-mgolden

A different golden testing provider for tasty.
Haskell
4
star
28

morpher

Transformation of ruby data-structures with optionally traced evaluation
Ruby
4
star
29

rz

Ruby ZeroMQ based jobserver with truly pulling workers
Ruby
3
star
30

openapi

OpenAPI datatypes
Haskell
3
star
31

axiom-sexp

Generate and load veritas relations from / to s-expressions
Ruby
3
star
32

lht

Lambda haskell tool / builds static binaries inside alpine containers
Haskell
3
star
33

db-migrations

Haskell Database Migrations for Postgresql
Haskell
3
star
34

ducktrap

The old soon to be unmaintained ducktrap. Successor is mbj/morpher
Ruby
3
star
35

source-constraints

GHC plugins to constrain the haskell source
Haskell
3
star
36

stack-deploy

Tooling around cloudformation templates
Haskell
3
star
37

mutant-rails-example

Mutant with rails example
Ruby
2
star
38

variable

Ruby concurrency variables MVar and IVar
Ruby
2
star
39

conversions

Haskell type conversions, another one.
Haskell
2
star
40

cbt

Container backend tool
2
star
41

devtools-hs

Haskell development tooling
Haskell
2
star
42

navigation

A web navigation dry up package
Ruby
1
star
43

sitemap_xml

Incomplete sitemap xml generator
Ruby
1
star
44

sunits

Depreciated sunits repo. Only used since some of my older projects will install from here!
Ruby
1
star
45

dump-parser

Simple and dump string 2 value DSL
Ruby
1
star
46

custom-resource

Custom CloudFormation Resources
Haskell
1
star
47

tinymagick

Simple ruby wrapper around imagemagick tools "identify" and "mogrify"
Ruby
1
star
48

html

Because XSS-free HTML generation is not about String#html_safe?
Ruby
1
star
49

mprelude

Very minimal prelude
Haskell
1
star
50

dm-annoing-modificators

Modification methods that raise on failure for datamapper.
Ruby
1
star
51

apk-build

My APK overlay and builder
Shell
1
star