HashyValidator is a custom Ruby on Rails validator designed to validate an array of hashes based on HashValidator criteria but also the following new criteria:
unique: A value within each hash that has to be unique across the whole array
Add this line to your application's Gemfile:
gem 'hashy_validator'And then execute:
$ bundle installOr install it yourself as:
$ gem install hashy_validatorTo leverage HashyValidator in your Rails model, follow these steps:
-
Add the gem to your Gemfile and run
bundle installas mentioned above. -
In your model, use the
validatemethod to apply thehashy_arrayvalidation.class YourModel < ApplicationRecord validates :pricing, hashy_array: { minutes: HashValidator.multiple('integer', 'unique'), price_cents: HashValidator.multiple('integer') } end
Customize each entry validators according to HashValidator criteria
rake testBug reports and pull requests are welcome. This project is intended to be a safe, welcoming space for collaboration. To ease up contribution we provide a VSCode devcontainer to run the project in a container.
Before submitting a PR do not forget to run all tests by doing rake test or against a single file ruby -I. test/validation_sqlite_test.rb.
The gem is available as open source under the terms of the MIT License.