Sha256: f2006a6b48156fa073c4a31faa45d5f3009f1fab9fdb63f49672cea29076fac5

Contents?: true

Size: 662 Bytes

Versions: 13

Compression:

Stored size: 662 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 nullable?(field)
        optional?(field) || field.type.type_sym == :null
      end

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

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
avromatic-5.2.0 lib/avromatic/model/field_helper.rb
avromatic-5.1.1 lib/avromatic/model/field_helper.rb
avromatic-5.1.0 lib/avromatic/model/field_helper.rb
avromatic-5.0.0 lib/avromatic/model/field_helper.rb
avromatic-4.3.0 lib/avromatic/model/field_helper.rb
avromatic-4.2.0 lib/avromatic/model/field_helper.rb
avromatic-4.1.1 lib/avromatic/model/field_helper.rb
avromatic-4.1.0 lib/avromatic/model/field_helper.rb
avromatic-4.0.0 lib/avromatic/model/field_helper.rb
avromatic-3.0.2 lib/avromatic/model/field_helper.rb
avromatic-3.0.1 lib/avromatic/model/field_helper.rb
avromatic-3.0.0 lib/avromatic/model/field_helper.rb
avromatic-2.4.0 lib/avromatic/model/field_helper.rb