Class: Jschematic::Attributes::MaxItems
- Inherits:
-
Object
- Object
- Jschematic::Attributes::MaxItems
- Includes:
- Element
- Defined in:
- lib/jschematic/attributes/max_items.rb
Instance Attribute Summary
Attributes included from Element
Instance Method Summary collapse
- #accepts?(instance) ⇒ Boolean
-
#initialize(max_items) ⇒ MaxItems
constructor
A new instance of MaxItems.
Methods included from Element
#required?, #schema_for, #title, #to_s
Constructor Details
#initialize(max_items) ⇒ MaxItems
Returns a new instance of MaxItems.
8 9 10 |
# File 'lib/jschematic/attributes/max_items.rb', line 8 def initialize(max_items) @max_items = max_items end |
Instance Method Details
#accepts?(instance) ⇒ Boolean
12 13 14 15 |
# File 'lib/jschematic/attributes/max_items.rb', line 12 def accepts?(instance) return true unless Array === instance (instance.length <= @max_items) || fail_validation!("at most #{@max_items}", instance.length) end |