Skip to content
This repository has been archived by the owner on May 31, 2022. It is now read-only.

kachick/struct-validatable

Repository files navigation

  • This repository is archived
  • No longer maintained
  • All versions have been yanked from https://rubygems.org for releasing valuable namespace for others

struct-validatable

Build Status

Struct will be able to have validators for each member

Usage

Require Ruby 2.7 or later

Add below code into your Gemfile

gem 'struct-validatable', '~> 0.3.0'

Overview

require 'struct/validatable'

Person = Struct.new :name do
  validator :name, AND(String, /\w+/)
end

person = Person.new
person.name = ''        #=> error
person.name = +'Foo Bar' #=> pass
person.valid?(:name)    #=> true
person.name.clear
person.valid?(:name)    #=> false
  • The pattern builder DSL is just using eqq
  • Supporting keyword_init: true

Links

License

MIT License - 2011 - Kenichi Kamiya