Module: Protobuf::Mongoid::Validations::ClassMethods
- Defined in:
- lib/protobuf/mongoid/validations.rb
Overview
Class Methods
Instance Method Summary collapse
-
#validates_enumeration_of(*args) ⇒ Object
Validates whether the value of the specified attribute is available in the given Protobuf Enum.
Instance Method Details
#validates_enumeration_of(*args) ⇒ Object
Validates whether the value of the specified attribute is available in the given Protobuf Enum. The enumeration should be passed as a class that defines the enumeration:
“‘ class User < Mongoid::Base
include ::Protobuf::Mongoid::Model
validates_enumeration_of :role_type, :with => RoleType, :allow_nil => true
end “‘
In this example, RoleType is a defined as a protobuf enum.
It accepts the same options as ‘validates_inclusion_of` (the :in option is automatically set and will be overwritten).
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/protobuf/mongoid/validations.rb', line 30 def validates_enumeration_of(*args) = args. enumerable = .delete(:with) raise ArgumentError, ':with must be specified' if enumerable.nil? [:in] = enumerable. if enumerable < ::Protobuf::Enum args << validates_inclusion_of(*args) end |