Class: Render::ArrayAttribute
- Defined in:
- lib/render/attributes/array_attribute.rb
Constant Summary collapse
- FAUX_DATA_UPPER_LIMIT =
5.freeze
- DEFAULT_NAME =
:render_array_attribute_untitled
Constants inherited from Attribute
Render::Attribute::SCHEMA_IDENTIFIERS
Instance Attribute Summary collapse
-
#max_items ⇒ Object
Returns the value of attribute max_items.
-
#min_items ⇒ Object
Returns the value of attribute min_items.
-
#simple ⇒ Object
Returns the value of attribute simple.
-
#unique ⇒ Object
Returns the value of attribute unique.
Attributes inherited from Attribute
#default, #enums, #exclusive_maximum, #exclusive_minimum, #format, #max_length, #maximum, #min_length, #minimum, #multiple_of, #name, #schema, #types
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ ArrayAttribute
constructor
A new instance of ArrayAttribute.
- #serialize(explicit_values = nil) ⇒ Object
Methods inherited from Attribute
#bias_type, #default_value, #nested_schema?
Constructor Details
#initialize(options = {}) ⇒ ArrayAttribute
Returns a new instance of ArrayAttribute.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/render/attributes/array_attribute.rb', line 13 def initialize( = {}) super self.name = .fetch(:title, DEFAULT_NAME).to_sym self.min_items = [:minItems] || 0 self.max_items = [:maxItems] self.unique = !![:uniqueItems] = .fetch(:items) () if .keys.include?(:properties) self.schema = Schema.new() else self.simple = true end end |
Instance Attribute Details
#max_items ⇒ Object
Returns the value of attribute max_items.
8 9 10 |
# File 'lib/render/attributes/array_attribute.rb', line 8 def max_items @max_items end |
#min_items ⇒ Object
Returns the value of attribute min_items.
8 9 10 |
# File 'lib/render/attributes/array_attribute.rb', line 8 def min_items @min_items end |
#simple ⇒ Object
Returns the value of attribute simple.
8 9 10 |
# File 'lib/render/attributes/array_attribute.rb', line 8 def simple @simple end |
#unique ⇒ Object
Returns the value of attribute unique.
8 9 10 |
# File 'lib/render/attributes/array_attribute.rb', line 8 def unique @unique end |
Instance Method Details
#serialize(explicit_values = nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/render/attributes/array_attribute.rb', line 31 def serialize(explicit_values = nil) explicit_values = faux_array_data if (Render.live == false && explicit_values.nil?) values = if simple explicit_values.collect do |value| value = (value || default_value) Type.to(types, value) end else explicit_values.collect do |value| schema.serialize!(value) end end unique ? values.uniq : values end |