Class: EnumFields::Definition
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- EnumFields::Definition
- Defined in:
- lib/enum_fields/definition.rb
Constant Summary collapse
- STANDARD_PROPERTIES =
%i[ value label ].freeze
Instance Attribute Summary collapse
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
Instance Method Summary collapse
- #data ⇒ Object
-
#initialize(data) ⇒ Definition
constructor
A new instance of Definition.
- #valid? ⇒ Boolean
Constructor Details
#initialize(data) ⇒ Definition
Returns a new instance of Definition.
12 13 14 15 16 17 18 19 20 |
# File 'lib/enum_fields/definition.rb', line 12 def initialize(data) @data = build(data) raise InvalidDefinitionsError, 'Definitions must be a Hash or Array' unless valid_hash?(@data) @properties = Set.new(STANDARD_PROPERTIES) @properties.merge(@data.flat_map { |_, | .keys }) super(@data) end |
Instance Attribute Details
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
10 11 12 |
# File 'lib/enum_fields/definition.rb', line 10 def properties @properties end |
Instance Method Details
#data ⇒ Object
22 23 24 |
# File 'lib/enum_fields/definition.rb', line 22 def data __getobj__ end |
#valid? ⇒ Boolean
26 27 28 |
# File 'lib/enum_fields/definition.rb', line 26 def valid? valid_hash?(__getobj__) end |