class NoSE::Serialize::FieldBuilder

Construct a field from a parsed hash

Public Instance Methods

call(_, fragment:, user_options:, **) click to toggle source
# File lib/nose/serialize.rb, line 40
def call(_, fragment:, user_options:, **)
  field_class = Fields::Field.subtype_class fragment['type']

  # Extract the correct parameters and create a new field instance
  if field_class == Fields::StringField && !fragment['size'].nil?
    field = field_class.new fragment['name'], fragment['size']
  elsif field_class.ancestors.include? Fields::ForeignKeyField
    entity = user_options[:entity_map][fragment['entity']]
    field = field_class.new fragment['name'], entity
  else
    field = field_class.new fragment['name']
  end

  field *= fragment['cardinality'] if fragment['cardinality']

  field
end