Class: Render::ArrayAttribute

Inherits:
Attribute show all
Defined in:
lib/render/array_attribute.rb

Constant Summary collapse

FAUX_DATA_UPPER_LIMIT =
5.freeze

Constants inherited from Attribute

Render::Attribute::SCHEMA_IDENTIFIERS

Instance Attribute Summary collapse

Attributes inherited from Attribute

#enums, #format, #name, #required, #schema, #type

Instance Method Summary collapse

Methods inherited from Attribute

#bias_type, #default_value, #nested_schema?

Constructor Details

#initialize(options = {}) ⇒ ArrayAttribute

Returns a new instance of ArrayAttribute.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/render/array_attribute.rb', line 9

def initialize(options = {})
  super

  self.name = options.fetch(:title, :render_array_attribute_untitled).to_sym
  options = options[:items]
  self.type = Render.parse_type(options[:type])
  self.format = Render.parse_type(options[:format]) rescue nil
  self.enums = options[:enum]

  if options.keys.include?(:properties)
    self.schema = Schema.new(options)
  else
    self.archetype = true
  end
end

Instance Attribute Details

#archetypeObject

Returns the value of attribute archetype.



7
8
9
# File 'lib/render/array_attribute.rb', line 7

def archetype
  @archetype
end

Instance Method Details

#serialize(explicit_values = nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/render/array_attribute.rb', line 25

def serialize(explicit_values = nil)
  explicit_values = faux_array_data if (Render.live == false && explicit_values.nil?)
  if archetype
    explicit_values.collect do |value|
      value || default_value
    end
  else
    explicit_values.collect do |value|
      schema.serialize!(value)
    end
  end
end