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