module Contentful::DatabaseImporter::ResourceBootstrapClassMethods

Bootstrap related Class Methods

Constants

TYPE_MAPPINGS

Public Instance Methods

array?(field_data) click to toggle source
# File lib/contentful/database_importer/resource_bootstrap_class_methods.rb, line 61
def array?(field_data)
  field_data[:type] == :array ||
    (resource?(field_data[:type]) &&
     %i[many through].include?(field_data[:relationship]))
end
basic_field_definition(field_data) click to toggle source
# File lib/contentful/database_importer/resource_bootstrap_class_methods.rb, line 76
def basic_field_definition(field_data)
  {
    id: field_data[:maps_to],
    name: field_data[:name],
    type: definition_type(field_data[:type])
  }
end
content_type_definition() click to toggle source
# File lib/contentful/database_importer/resource_bootstrap_class_methods.rb, line 98
def content_type_definition
  {
    id: content_type_id,
    name: content_type_name,
    displayField: display_field,
    fields: fields_definition
  }
end
definition_type(type) click to toggle source
# File lib/contentful/database_importer/resource_bootstrap_class_methods.rb, line 17
def definition_type(type)
  if type == :string
    type = :symbol
  elsif link?(type)
    type = :link
  end

  TYPE_MAPPINGS[type]
end
field_definition(field_data) click to toggle source
# File lib/contentful/database_importer/resource_bootstrap_class_methods.rb, line 84
def field_definition(field_data)
  definition = basic_field_definition(field_data)

  definition[:type] = 'Array' if array?(field_data)
  definition[:linkType] = link_type(field_data[:type]) if link_type?(field_data)
  definition[:items] = items_type(field_data) if array?(field_data)

  definition
end
fields_definition() click to toggle source
# File lib/contentful/database_importer/resource_bootstrap_class_methods.rb, line 94
def fields_definition
  fields.reject { |f| f[:exclude_from_output] }.map { |f| field_definition(f) }
end
items_type(field_data) click to toggle source
# File lib/contentful/database_importer/resource_bootstrap_class_methods.rb, line 34
def items_type(field_data)
  return { type: 'Link', linkType: array_link_type(field_data) } if array_link?(field_data)

  type = definition_type(field_data[:item_type])

  error = 'Array item type could not be mapped for '
  error += field_data[:maps_to].to_s
  raise error if type.nil?

  { type: type }
end
resource?(other) click to toggle source
# File lib/contentful/database_importer/resource_bootstrap_class_methods.rb, line 67
def resource?(other)
  return false unless other.respond_to?(:ancestors)
  other.ancestors.include?(::Contentful::DatabaseImporter::Resource)
end