Sha256: cbd9ced32da0cd7b0de9ec6561ed185103ee16082bd99e98d85a8f738a46cb61

Contents?: true

Size: 731 Bytes

Versions: 24

Compression:

Stored size: 731 Bytes

Contents

require 'active_support/core_ext/hash/keys'

module JSONAPIonify::Types
  class ObjectType < BaseType

    loader do |value|
      raise LoadError, 'invalid type' unless value.is_a?(Hash)
      super(value).deep_symbolize_keys
    end

    dumper do |value|
      raise DumpError, 'cannot convert value to hash' unless value.respond_to?(:to_h)
      value = value.to_h.tap do |hash|
        raise DumpError, 'output value was not a hash' unless hash.is_a? Hash
      end
      super(value.deep_stringify_keys)
    end

    def sample(field_name)
      field_name = field_name.to_s.singularize.to_sym
      %i{foo bar baz}.each_with_object({}) do |k, h|
        h[k] = StringType.new.sample(field_name)
      end
    end

  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
jsonapionify-0.12.10 lib/jsonapionify/types/object_type.rb
jsonapionify-0.12.9 lib/jsonapionify/types/object_type.rb
jsonapionify-0.12.8 lib/jsonapionify/types/object_type.rb
jsonapionify-0.12.7 lib/jsonapionify/types/object_type.rb
jsonapionify-0.12.5 lib/jsonapionify/types/object_type.rb
jsonapionify-0.12.4 lib/jsonapionify/types/object_type.rb
jsonapionify-0.12.3 lib/jsonapionify/types/object_type.rb
jsonapionify-0.12.2 lib/jsonapionify/types/object_type.rb
jsonapionify-0.12.1 lib/jsonapionify/types/object_type.rb
jsonapionify-0.12.0 lib/jsonapionify/types/object_type.rb
jsonapionify-0.11.11 lib/jsonapionify/types/object_type.rb
jsonapionify-0.11.10 lib/jsonapionify/types/object_type.rb
jsonapionify-0.11.9 lib/jsonapionify/types/object_type.rb
jsonapionify-0.11.8 lib/jsonapionify/types/object_type.rb
jsonapionify-0.11.7 lib/jsonapionify/types/object_type.rb
jsonapionify-0.11.6 lib/jsonapionify/types/object_type.rb
jsonapionify-0.11.5 lib/jsonapionify/types/object_type.rb
jsonapionify-0.11.0 lib/jsonapionify/types/object_type.rb
jsonapionify-0.10.2 lib/jsonapionify/types/object_type.rb
jsonapionify-0.10.1 lib/jsonapionify/types/object_type.rb