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
array_link?(field_data)
click to toggle source
# File lib/contentful/database_importer/resource_bootstrap_class_methods.rb, line 46 def array_link?(field_data) (field_data[:type] == :array && field_data[:item_type] == :asset) || (resource?(field_data[:type]) && %i[many through].include?(field_data[:relationship])) end
array_link_type(field_data)
click to toggle source
# File lib/contentful/database_importer/resource_bootstrap_class_methods.rb, line 52 def array_link_type(field_data) return 'Asset' if field_data[:item_type] == :asset return 'Entry' if resource?(field_data[:type]) 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
link?(type)
click to toggle source
# File lib/contentful/database_importer/resource_bootstrap_class_methods.rb, line 57 def link?(type) type == :asset || resource?(type) end
link_type(type)
click to toggle source
# File lib/contentful/database_importer/resource_bootstrap_class_methods.rb, line 27 def link_type(type) return 'Asset' if type == :asset return 'Entry' if resource?(type) raise 'Type class is not a valid Link' end
link_type?(field_data)
click to toggle source
# File lib/contentful/database_importer/resource_bootstrap_class_methods.rb, line 72 def link_type?(field_data) link?(field_data[:type]) && !array_link?(field_data) 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