module DataModel # Test data for hash schemas module Fixtures::Hash include Fixtures extend self # hash data conforming to the contact schema # @return [Hash{Symbol => String}] the hash def example_contact { first_name: "foo", last_name: "bar", email: "foo@bar.com" } end # alternate hash syntax for when you want to type keys and values # @return [Example] the example def dictionary Example.new( [:hash, [symbol: :string]], variants: { valid: { foo: "bar" }, invalid: { foo: 123 } }, ) end # hash contact example # @return [Example] the example def contact Example.new( [:hash, [:first_name, :string], [:last_name, :string, { optional: true }], [:email, :string]], variants: { valid: example_contact, missing: nil, coercible: example_contact.to_a, missing_email: example_contact.tap { |h| h.delete(:email) }, invalid_field: example_contact.merge(email: 123), other_type: [] }, ) end # hash contact example that is optional # @return [Example] the example def optional_contact Example.new( [:hash, { optional: true }, [:first_name, :string], [:last_name, :string, { optional: true }], [:email, :string]], variants: { valid: example_contact, missing: nil }, ) end # hash contact example that is closed to extra keys # @return [Example] the example def closed_contact Example.new( [:hash, { open: false }, [:first_name, :string], [:last_name, :string, { optional: true }], [:email, :string]], variants: { valid: example_contact, extra_keys: example_contact.merge(extra: "keys") }, ) end end end