Class: Contentful::DatabaseImporter::IdGenerator::Base
- Inherits:
-
Object
- Object
- Contentful::DatabaseImporter::IdGenerator::Base
- Defined in:
- lib/contentful/database_importer/id_generator/base.rb
Overview
Base Id Generator
Direct Known Subclasses
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #find(entry_data, index, match) ⇒ Object
- #find_on_entry(entry_data, match) ⇒ Object
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
- #run(entry_data, index) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
8 9 10 |
# File 'lib/contentful/database_importer/id_generator/base.rb', line 8 def initialize( = {}) @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/contentful/database_importer/id_generator/base.rb', line 6 def @options end |
Instance Method Details
#find(entry_data, index, match) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/contentful/database_importer/id_generator/base.rb', line 18 def find(entry_data, index, match) return [match] if .key?(match) return index.to_s if match == :index find_on_entry(entry_data, match) end |
#find_on_entry(entry_data, match) ⇒ Object
25 26 27 28 29 30 |
# 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) ⇒ Object
12 13 14 15 16 |
# File 'lib/contentful/database_importer/id_generator/base.rb', line 12 def run(entry_data, index) .fetch(:template, '').gsub(/\{\{([\w|\.]+)\}\}/) do |match| find(entry_data, index, match.gsub('{{', '').gsub('}}', '').to_sym) end end |