class Contentful::DatabaseImporter::IdGenerator::Base
Base
Id Generator
Attributes
options[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/contentful/database_importer/id_generator/base.rb, line 8 def initialize(options = {}) @options = options end
Public Instance Methods
find(entry_data, index, match)
click to toggle source
# File lib/contentful/database_importer/id_generator/base.rb, line 18 def find(entry_data, index, match) return options[match] if options.key?(match) return index.to_s if match == :index find_on_entry(entry_data, match) end
find_on_entry(entry_data, match)
click to toggle source
# File lib/contentful/database_importer/id_generator/base.rb, line 25 def find_on_entry(entry_data, match) return entry_data.excluded_fields[match] if entry_data.excluded_fields.key?(match) return entry_data.bootstrap_fields[match] if entry_data.bootstrap_fields.key?(match) raise "Template could not be resolved, #{match} not found." end
run(entry_data, index)
click to toggle source
# File lib/contentful/database_importer/id_generator/base.rb, line 12 def run(entry_data, index) options.fetch(:template, '').gsub(/\{\{([\w|\.]+)\}\}/) do |match| find(entry_data, index, match.gsub('{{', '').gsub('}}', '').to_sym) end end