
Company News
Meet the Socket Team at RSAC and BSidesSF 2026
Join Socket for live demos, rooftop happy hours, and one-on-one meetings during BSidesSF and RSA 2026 in San Francisco.
valid
Advanced tools
Validator is a simple ruby validation class. You don't use it directly inside your classes like just about every other ruby validation class out there. I chose to implement it in this way so I didn't automatically pollute the namespace of the objects I wanted to validate.
This also solves the problem of validating forms very nicely. Frequently you will have a form that represents many different data objects in your system, and you can pre-validate everything before doing any saving.
Validator is useful for validating the state of any existing ruby object.
object = OpenStruct.new(:email => 'foo@bar.com', :password => 'foobar')
validator = Validation::Validator.new(object)
validator.rule(:email, [:email, :not_empty]) # multiple rules in one line
validator.rule(:password, :not_empty) # a single rule on a line
validator.rule(:password, :length => {:minimum => 3}) # a rule that takes parameters
if validator.valid?
# save the data somewhere
else
@errors = validator.errors
end
The first paramater can be any message that the object responds to.
If you have a custom rule you need to write, just put it inside the Validation::Rule namespace:
module Validation
module Rule
class MyCustomRule
def error_key
:my_custom_rule
end
def valid_value?(value)
# Logic for determining the validity of the value
end
def params
{}
end
end
end
end
A rule class should have the following methods on it:
error_key a symbol to represent the error. This shows up in the errors hash. Must be an underscored_version of the class namevalid_value?(value) the beef of the rule. This is where you determine if the value is valid or notparams the params hash that was passed into the constructorYou can also create self-contained validation classes if you don't like the dynamic creation approach:
require 'validation'
require 'validation/rule/not_empty'
class MyFormValidator < Validation::Validator
include Validation
rule :email, :not_empty
end
Now you can use this anywhere in your code:
form_validator = MyFormValidator.new(OpenStruct.new(params))
form_validator.valid?
Have an improvement? Have an awesome rule you want included? Simple!
develop branchdevelop branchDon't change any version files or gemspec files in your change.
FAQs
Unknown package
We found that valid demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Company News
Join Socket for live demos, rooftop happy hours, and one-on-one meetings during BSidesSF and RSA 2026 in San Francisco.

Research
/Security News
Malicious Packagist packages disguised as Laravel utilities install an encrypted PHP RAT via Composer dependencies, enabling remote access and C2 callbacks.

Research
/Security News
OpenVSX releases of Aqua Trivy 1.8.12 and 1.8.13 contained injected natural-language prompts that abuse local AI coding agents for system inspection and potential data exfiltration.