https://github.com/wilsonsilva/activemodel-extra_validations
Extra ActiveModel validations
https://github.com/wilsonsilva/activemodel-extra_validations
Last synced: 7 months ago
JSON representation
Extra ActiveModel validations
- Host: GitHub
- URL: https://github.com/wilsonsilva/activemodel-extra_validations
- Owner: wilsonsilva
- License: mit
- Created: 2021-02-19T22:14:45.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-05-31T23:53:45.000Z (over 4 years ago)
- Last Synced: 2025-02-24T05:13:48.611Z (8 months ago)
- Language: Ruby
- Size: 42 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Activemodel::ExtraValidations
[](https://badge.fury.io/rb/activemodel-extra_validations)
[](https://travis-ci.org/wilsonsilva/activemodel-extra_validations)
[](https://codeclimate.com/github/wilsonsilva/activemodel-extra_validations/maintainability)
[](https://codeclimate.com/github/wilsonsilva/activemodel-extra_validations/test_coverage)
[](https://hakiri.io/github/wilsonsilva/activemodel-extra_validations/master)
[](http://inch-ci.org/github/wilsonsilva/activemodel-extra_validations)Common ActiveModel/ActiveRecord validations.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'activemodel-extra_validations'
```And then execute:
$ bundle install
Or install it yourself as:
$ gem install activemodel-extra_validations
## Usage
### presence_of_at_least_one_of
Validates that at least one of the supplied attributes are given.
```ruby
require 'activemodel/extra_validations/presence_of_at_least_one_of'class BillingDetails
include ActiveModel::Model
include ActiveModel::Validations
include ActiveModel::Attributesattribute :credit_card
attribute :debit_cardvalidate_presence_of_at_least_one_of :credit_card, :debit_card
endbilling_details = BillingDetails.new
billing_details.valid?
billing_details.errors.full_messages # => [
# 'Debit card is missing. At least one of [:credit_card, :debit_card] must be present',
# 'Credit card is missing. At least one of [:credit_card, :debit_card] must be present'
# ]
```## Development
After checking out the repo, run `bin/setup` to install dependencies, configure git hooks and create support files.
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
The health and maintainability of the codebase is ensured through a set of
Rake tasks to test, lint and audit the gem for security vulnerabilities and documentation:```
rake bundle:audit # Checks for vulnerable versions of gems
rake qa # Test, lint and perform security and documentation audits
rake rubocop # Lint the codebase with RuboCop
rake rubocop:auto_correct # Auto-correct RuboCop offenses
rake spec # Run RSpec code examples
rake verify_measurements # Verify that yardstick coverage is at least 100%
rake yard # Generate YARD Documentation
rake yard:junk # Check the junk in your YARD Documentation
rake yardstick_measure # Measure docs in lib/**/*.rb with yardstick
```## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/wilsonsilva/activemodel-extra_validations.
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to
the [code of conduct](https://github.com/wilsonsilva/activemodel-extra_validations/blob/master/CODE_OF_CONDUCT.md).## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
## Code of Conduct
Everyone interacting in the Activemodel::ExtraValidations project's codebases, issue trackers, chat rooms and mailing
lists is expected to follow the [code of conduct](https://github.com/wilsonsilva/activemodel-extra_validations/blob/master/CODE_OF_CONDUCT.md).