
Research
/Security News
npm Author Qix Compromised via Phishing Email in Major Supply Chain Attack
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.
Cavalry is whole data validation DSL.
The situation: When you need to validate some data, with foreign-key or has some constraints on associations(like Online-game's master-data), you need to insert all data first for validation.
Cavalry can:
Add this line to your application's Gemfile:
gem 'cavalry'
And then execute:
$ bundle
Or install it yourself as:
$ gem install cavalry
Here is example model and validator!
class Person < ActiveRecord::Base
has_many :books
has_one :life
end
# 1. inherit Cavalry::Validator to define validator
class PersonValidator < Cavalry::Validator
# 2. call Cavalry::Validator.validate_for, to define target model
validate_for Person
# 3. pass a block to Cavalry::Validator.validate_each. it runs EVERY data-record.
validate_each do
# people needs life...
validates :life, presence: true
validate :name_is_downcased
def name_is_downcased
if name != name.downcase
errors.add(:name, "should be downcase.")
end
end
end
# 4. pass a block to Cavalry::Validator.validate_group. it runs ONCE for whole data-record
validate_group do
# 5. call validate and give it block. it receives Person.all as argument "records"
validate do |records|
return unless records.count > 5
errors.add(:base, "Too many people.")
end
# 5. call validate and chain any methods. it receives Person.method as argument "records"
validate.where(name: "bob") do |records|
return if records.count == 1
errors.add(:base, "bob must be unique.")
end
# 6. call validate with symbol, it calls method that you defined same scope.
validate :books_are_unique
def number_of_books
all_books = Person.all.flat_map(&:book)
return if all_books == all_books.uniq
errors.add(:books, "books that people have should be unique")
end
end
end
Here is sample rake task file. I'm waiting some PR for improve!
namespace :data do
task check: :environment do
Cavalry.configure do |config|
config.modelss_path = "app/models"
config.validators_path = "app/validators"
end
unless Cavalry.valid?
print Cavalry.dump.to_yaml
end
end
end
Then,
bundle exec rake data:check
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/the40san/cavalry.
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that cavalry 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.
Research
/Security News
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.