Class: Jschematic::Attributes::Enum

Inherits:
Object
  • Object
show all
Includes:
Element
Defined in:
lib/jschematic/attributes/enum.rb

Instance Attribute Summary

Attributes included from Element

#id, #parent

Instance Method Summary collapse

Methods included from Element

#required?, #schema_for, #title, #to_s

Constructor Details

#initialize(enum) ⇒ Enum

Returns a new instance of Enum.



8
9
10
11
# File 'lib/jschematic/attributes/enum.rb', line 8

def initialize(enum)
  raise "Enum requires an Array of possible values" unless Array === enum
  @enum = enum
end

Instance Method Details

#accepts?(instance) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/jschematic/attributes/enum.rb', line 13

def accepts?(instance)
  @enum.any?{ |e| e == instance } || fail_validation!("one of #{@enum}", instance)
end