Module: StoreModel::Enum
- Defined in:
- lib/store_model/enum.rb
Overview
Allows defining Rails-like enums
Instance Method Summary collapse
-
#enum(name, values = nil, **kwargs) ⇒ Object
Defines new enum.
Instance Method Details
#enum(name, values = nil, **kwargs) ⇒ Object
Defines new enum
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/store_model/enum.rb', line 11 def enum(name, values = nil, **kwargs) values ||= kwargs[:in] || kwargs = (kwargs) ensure_hash(values).tap do |mapping| define_attribute(name, mapping, ) define_reader(name, mapping) define_writer(name, mapping, [:raise_on_invalid_values]) define_method("#{name}_value") { attributes[name.to_s] } define_map_readers(name, mapping) define_predicate_methods(name, mapping, ) end end |