Method: OpenGraphReader::Object::DSL#enum

Defined in:
lib/open_graph_reader/object/dsl/types.rb

#enum(name, allowed, options = {}) ⇒ Object

Parameters:

  • allowed (Array<String>)

    the list of allowed values

  • name (Symbol)

    the name of the property in the current namespace

  • options ({Symbol => Bool, Class, Array<String>}) (defaults to: {})

    additional options

Options Hash (options):

  • :required (Bool) — default: false

    Make the property required.

  • :collection (Bool) — default: false

    This property can occur multiple times.

  • :to (Class)

    This property maps to the given object (optional). belongs to the given verticals of the object (optional).

  • :verticials (Array<String>)

    This property

  • :downcase (Bool) — default: false

    Normalize the contents case to lowercase.

See Also:



58
59
60
61
62
63
64
65
66
67
# File 'lib/open_graph_reader/object/dsl/types.rb', line 58

define_type_no_doc :enum do |value, allowed, options|
  value = value.to_s

  unless allowed.include? value
    next unless options[:required] || !OpenGraphReader.config.discard_invalid_optional_properties
    raise InvalidObjectError, "Expected one of #{allowed.inspect} but was #{value.inspect}"
  end

  value
end