Module: Avromatic::Model::FieldHelper

Extended by:
FieldHelper
Included in:
FieldHelper
Defined in:
lib/avromatic/model/field_helper.rb

Instance Method Summary collapse

Instance Method Details

#boolean?(field) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
# File 'lib/avromatic/model/field_helper.rb', line 23

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

#nullable?(field) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/avromatic/model/field_helper.rb', line 19

def nullable?(field)
  optional?(field) || field.type.type_sym == :null
end

#optional?(field) ⇒ Boolean

An optional field is represented as a union where the first member is null.

Returns:

  • (Boolean)


10
11
12
13
# File 'lib/avromatic/model/field_helper.rb', line 10

def optional?(field)
  field.type.type_sym == :union &&
    field.type.schemas.first.type_sym == :null
end

#required?(field) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/avromatic/model/field_helper.rb', line 15

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