class Render::HashAttribute

Attributes

required[RW]

Public Class Methods

new(options = {}) click to toggle source
Calls superclass method Render::Attribute::new
# File lib/render/attributes/hash_attribute.rb, line 8
def initialize(options = {})
  super

  self.name = options.keys.first
  options = options[name]

  process_options!(options)
  self.required = !!options[:required]

  initialize_schema!(options) if nested_schema?(options)
end

Public Instance Methods

initialize_schema!(options) click to toggle source
# File lib/render/attributes/hash_attribute.rb, line 20
def initialize_schema!(options)
  schema_options = {
    title: name,
    type: bias_type
  }

  self.schema = Schema.new(schema_options.merge(options))
end
serialize(explicit_value, maintain_nil = false) click to toggle source
# File lib/render/attributes/hash_attribute.rb, line 29
def serialize(explicit_value, maintain_nil = false)
  if !!schema
    value = schema.serialize!(explicit_value)
    { name.to_sym => value }
  else
    if (maintain_nil && !explicit_value)
      value = explicit_value
    else
      value = (explicit_value || default_value)
    end

    { name.to_sym => Type.to(types, value) }
  end
end