Sha256: fb9f45692368b0f70dfd7c565faef1f018e79b35d390fcbaaba7fb1dc99365ed

Contents?: true

Size: 746 Bytes

Versions: 6

Compression:

Stored size: 746 Bytes

Contents

Schema = _ = StrongJSON.new do
  # @type self: AddressSchema

  let :address, object(address: string, country: symbol?)
  let :email, object(email: string)
  let :contact, enum?(address, email)
  let :person, object(name: string, contacts: array(contact))
end

person = Schema.person.coerce(nil)

# @type var name: String
name = person[:name]

# @type var contacts: Array<email | address>
contacts = person[:contacts]

contacts.each do |contact|
    case 
    when contact.keys.include?(:email)
        # @type var contact: email
        puts "Email: #{contact[:email]}"
    when contact.keys.include?(:address)
        # @type var contact: address
        puts "Address: #{contact[:address]} (#{contact[:country] || "unspecified"})"
    end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
strong_json-2.1.0 example/example.rb
strong_json-2.0.0 example/example.rb
strong_json-1.1.0 example/example.rb
strong_json-1.0.1 example/example.rb
strong_json-1.0.0 example/example.rb
strong_json-0.9.0 example/example.rb