项目作者: gemologist

项目描述 :
Duck type validators for active model
高级语言: Ruby
项目地址: git://github.com/gemologist/active_model-validations-duck_type.git
创建时间: 2017-12-13T17:08:20Z
项目社区:https://github.com/gemologist/active_model-validations-duck_type

开源协议:MIT License

下载


ActiveModel::Validations::DuckType

Duck type validators for active model.

ActiveModel::Validations was sorely lacking a system to validate the type. To respect Ruby, duck type.

Installation

Add this line to your application’s Gemfile:

  1. gem 'active_model-validations-duck_type'

And then execute:

  1. $ bundle

Or install it yourself as:

  1. $ gem install active_model-validations-duck_type

Usage

  1. class Person
  2. include ActiveModel::Validations
  3. attr_accessor :pet
  4. validates :pet, duck_type: { all: %i[house food] }
  5. end
  6. person = Person.new
  7. person.pet = 'house'
  8. person.valid? # => false
  9. class Parrot
  10. attr_accessor :house, :food
  11. end
  12. person.pet = Parrot.new
  13. person.valid? # => true

Contributing

Bug reports and pull requests are welcome on GitHub.

License

The gem is available as open source under the terms of the MIT License.