Module: GOBL::Enum
- Included in:
- Currency::Code, L10n::CountryCode, Org::Unit
- Defined in:
- lib/gobl/enum.rb
Overview
Base class for single value structures in the GOBL schema that have a controlled set of values associated to them (i.e., an enumeration) that may constrain them
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/gobl/enum.rb', line 7 def self.included(base) base.include ActiveModel::Validations base.class_eval do validate :valid_enum_value, if: :strict_enum? end end |
Instance Method Details
#description ⇒ Object
15 16 17 |
# File 'lib/gobl/enum.rb', line 15 def description self.class::ENUM.fetch(self, self) end |
#valid_enum_value ⇒ Object
19 20 21 |
# File 'lib/gobl/enum.rb', line 19 def valid_enum_value errors.add(:base, "Value \"#{self}\" is not within the allowed values of the enumeration") unless self.class::ENUM.key?(self) end |