Class: Jschematic::Attributes::Enum
- Inherits:
-
Object
- Object
- Jschematic::Attributes::Enum
- Includes:
- Element
- Defined in:
- lib/jschematic/attributes/enum.rb
Instance Attribute Summary
Attributes included from Element
Instance Method Summary collapse
- #accepts?(instance) ⇒ Boolean
-
#initialize(enum) ⇒ Enum
constructor
A new instance of Enum.
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
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 |