Sha256: 772ae47757d16e104382a807d9df21d717c27622ba21d5f82c5dedc953c58270

Contents?: true

Size: 579 Bytes

Versions: 10

Compression:

Stored size: 579 Bytes

Contents

# frozen_string_literal: true

module Avromatic
  module Model
    module FieldHelper
      extend self

      # An optional field is represented as a union where the first member
      # is null.
      def optional?(field)
        field.type.type_sym == :union &&
          field.type.schemas.first.type_sym == :null
      end

      def required?(field)
        !optional?(field)
      end

      def boolean?(field)
        field.type.type_sym == :boolean ||
          (FieldHelper.optional?(field) && field.type.schemas.last.type_sym == :boolean)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
avromatic-2.3.0 lib/avromatic/model/field_helper.rb
avromatic-2.2.6 lib/avromatic/model/field_helper.rb
avromatic-2.2.5 lib/avromatic/model/field_helper.rb
avromatic-2.2.4 lib/avromatic/model/field_helper.rb
avromatic-2.2.3 lib/avromatic/model/field_helper.rb
avromatic-2.2.2 lib/avromatic/model/field_helper.rb
avromatic-2.2.1 lib/avromatic/model/field_helper.rb
avromatic-2.2.0 lib/avromatic/model/field_helper.rb
avromatic-2.1.0 lib/avromatic/model/field_helper.rb
avromatic-2.0.1 lib/avromatic/model/field_helper.rb