Sha256: 18c40ae4b9e3d82081186b1b5ed13245e94422a101f57ac4492a6af995206a4f

Contents?: true

Size: 874 Bytes

Versions: 1

Compression:

Stored size: 874 Bytes

Contents

require "render"
require "render/attribute"

module Render
  class HashAttribute < Attribute
    def initialize(options = {})
      super

      self.name = options.keys.first
      options = options[name]
      self.type = Render.parse_type(options[:type])
      self.format = Render.parse_type(options[:format]) rescue nil
      self.enums = options[:enum]

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

    def initialize_schema!(options)
      schema_options = {
        title: name,
        type: bias_type
      }

      self.schema = Schema.new(schema_options.merge(options))
    end

    def serialize(explicit_value)
      if !!schema
        value = schema.serialize!(explicit_value)
        { name.to_sym => value }
      else
        value = (explicit_value || default_value)
        { name.to_sym => value }
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
render-0.0.3 lib/render/hash_attribute.rb