Class: MediaTypes::Scheme::EnumerationOfType

Inherits:
Object
  • Object
show all
Defined in:
lib/media_types/scheme/enumeration_of_type.rb

Instance Method Summary collapse

Constructor Details

#initialize(item_type, enumeration_type: Array, allow_empty: false) ⇒ EnumerationOfType

An attribute that expects a value of type enumeration_type and each item of type item_type

Parameters:

  • item_type (Class)

    the type of each item

  • enumeration_type (Class) (defaults to: Array)

    the type of the enumeration as a whole

  • allow_empty (TrueClass, FalseClass) (defaults to: false)

    if true, an empty instance of enumeration_type is valid



16
17
18
19
20
21
22
# File 'lib/media_types/scheme/enumeration_of_type.rb', line 16

def initialize(item_type, enumeration_type: Array, allow_empty: false)
  self.item_type = item_type
  self.enumeration_type = enumeration_type
  self.allow_empty = allow_empty

  freeze
end

Instance Method Details

#inspectObject



30
31
32
# File 'lib/media_types/scheme/enumeration_of_type.rb', line 30

def inspect
  "[Scheme::EnumerationOfType #{item_type} collection=#{enumeration_type} empty=#{allow_empty}]"
end

#validate!(output, options, **_opts) ⇒ Object



24
25
26
27
28
# File 'lib/media_types/scheme/enumeration_of_type.rb', line 24

def validate!(output, options, **_opts)
  validate_enumeration!(output, options) &&
    validate_not_empty!(output, options) &&
    validate_items!(output, options)
end