Sha256: 244bfa478e466ecae69f15650f83f7f39ba5cf5db8c4f756357b7ed1b226617a

Contents?: true

Size: 889 Bytes

Versions: 4

Compression:

Stored size: 889 Bytes

Contents

require "render"
require "render/attributes/attribute"

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

      self.name = options.keys.first
      options = options[name]
      process_type!(options)

      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, 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 => value }
      end
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
render-0.0.8 lib/render/attributes/hash_attribute.rb
render-0.0.7 lib/render/attributes/hash_attribute.rb
render-0.0.6 lib/render/attributes/hash_attribute.rb
render-0.0.5 lib/render/attributes/hash_attribute.rb