Socket
Book a DemoInstallSign in
Socket

data_validator

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

data_validator

0.1.1
bundlerRubygems
Version published
Maintainers
1
Created
Source

DataValidator Build Status

DataValidator is validation everywhere.
For Example, Controller or else.

Sample

params = {foo: 'foo', bar: 'bar'}

validator = DataValidator::Validator.new(
  params,
  {foo: {length: {is: 4}}},
  {bar: {presence: true, format: {with: /\A[a-zA-Z]+\z/}}}
)

unless validator.valid?
  @errors = validator.errors
end

@errors
=> {
  foo: ["is the wrong length (should be 4 characters)"],
  bar: ["can't be blank", "is invalid"]
}

Validation logic

DataValidator has almost AR validation logics by default.

  • acceptance
  • confirmation
  • format
  • inclusion
  • length
  • numericality
  • presence

Error message

DataValidator supports i18n.
If you use rails, you not worry about locale file.

Original Validation

Ex)

# encoding: UTF-8

module DataValidator
  class TestValidator < BaseValidator
    def validate
      if options && values !~ /[^@]+$/
        error_add :invalid_test, test: value
      end
    end
  end
end

BaseValidator set accessors below.

  • name : validating parmater name
  • value : validating paramter value
  • options : validation rules

Please see test case.

An error message subject uses "datavalidator.attribute.#{name}" in i18n locale file or name.

Installation

Add this line to your application's Gemfile:

gem 'data_validator'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install data_validator

Usage

require 'data_validator'

Contributing

  • Fork it
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Added some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create new Pull Request

Copyright (c) 2012- HARUAYMA Makoto (SpringMT)

License

MIT (see MIT-LICENSE)

FAQs

Package last updated on 11 Mar 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.