module Contentful::DatabaseImporter::ResourceFieldClassMethods

Field related Class Methods for Resource

Public Instance Methods

fetch_many_relationship_options(field, options) click to toggle source
# File lib/contentful/database_importer/resource_field_class_methods.rb, line 37
def fetch_many_relationship_options(field, options)
  field[:id_field] = options.fetch(:id_field)
  field[:key] = options.fetch(:key)
end
fetch_one_relationship_options(field, options)
fetch_relationship_options(field, options) click to toggle source
# File lib/contentful/database_importer/resource_field_class_methods.rb, line 51
def fetch_relationship_options(field, options)
  field[:relationship] = options.fetch(:relationship)

  send(
    "fetch_#{options.fetch(:relationship)}_relationship_options",
    field,
    options
  )
end
fetch_through_relationship_options(field, options) click to toggle source
# File lib/contentful/database_importer/resource_field_class_methods.rb, line 43
def fetch_through_relationship_options(field, options)
  field[:through] = options.fetch(:through)
  field[:primary_id_field] = options.fetch(:primary_id_field)
  field[:foreign_id_field] = options.fetch(:foreign_id_field)
  field[:primary_key] = options.fetch(:primary_key)
  field[:foreign_key] = options.fetch(:foreign_key)
end
field(database_name, options = {}) click to toggle source
# File lib/contentful/database_importer/resource_field_class_methods.rb, line 5
def field(database_name, options = {})
  @fields ||= []
  @fields << prepare_field(database_name, options)
end
fields() click to toggle source
# File lib/contentful/database_importer/resource_field_class_methods.rb, line 10
def fields
  @fields || []
end
prepare_field(database_name, options) click to toggle source
# File lib/contentful/database_importer/resource_field_class_methods.rb, line 29
def prepare_field(database_name, options)
  field = prepare_standard_field_options(database_name, options)
  field[:item_type] = options.fetch(:item_type) if field[:type] == :array
  fetch_relationship_options(field, options) if options.fetch(:relationship, false)

  field
end
prepare_standard_field_options(database_name, options) click to toggle source
# File lib/contentful/database_importer/resource_field_class_methods.rb, line 18
def prepare_standard_field_options(database_name, options)
  {
    db_name: database_name,
    maps_to: options.fetch(:maps_to, database_name),
    name: options.fetch(:name, database_name),
    type: options.fetch(:type),
    pre_process: options.fetch(:pre_process, nil),
    exclude_from_output: options.fetch(:exclude_from_output, false)
  }
end
relationship_fields() click to toggle source
# File lib/contentful/database_importer/resource_field_class_methods.rb, line 14
def relationship_fields
  @fields.select { |f| resource?(f[:type]) }
end