Class: SerializeAttributes::Types::Enum
- Inherits:
-
Object
- Object
- SerializeAttributes::Types::Enum
- Defined in:
- lib/serialize_attributes/types/enum.rb
Overview
A custom type which can only hold one of a set of predetermined values.
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #attach_validations_to(object, field_name) ⇒ Object
-
#initialize(of: [], type: nil) ⇒ Enum
constructor
Construct a type instance.
Constructor Details
#initialize(of: [], type: nil) ⇒ Enum
Construct a type instance.
27 28 29 30 |
# File 'lib/serialize_attributes/types/enum.rb', line 27 def initialize(of: [], type: nil) @options = of.freeze @type = resolve_type(type) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/serialize_attributes/types/enum.rb', line 9 def @options end |
Instance Method Details
#attach_validations_to(object, field_name) ⇒ Object
32 33 34 |
# File 'lib/serialize_attributes/types/enum.rb', line 32 def attach_validations_to(object, field_name) object.validates_inclusion_of(field_name, in: @options) end |