class Contentful::Exporter::Drupal::FileManaged

Attributes

config[R]
exporter[R]

Public Class Methods

new(exporter, config) click to toggle source
# File lib/drupal/file_managed.rb, line 8
def initialize(exporter, config)
  @exporter, @config = exporter, config
end

Public Instance Methods

save_files_as_json() click to toggle source
# File lib/drupal/file_managed.rb, line 12
def save_files_as_json
  exporter.create_directory("#{config.assets_dir}/file")
  config.db[:file_managed].each do |file_row|
    extract_data(file_row)
  end
end

Private Instance Methods

extract_data(file_row) click to toggle source
# File lib/drupal/file_managed.rb, line 21
def extract_data(file_row)
  puts "Saving file - id: #{file_row[:fid]}"
  db_object = map_fields(file_row)
  exporter.write_json_to_file("#{config.assets_dir}/file/#{db_object[:id]}.json", db_object)
end
id(file_id) click to toggle source
# File lib/drupal/file_managed.rb, line 35
def id(file_id)
  "file_#{file_id}"
end
map_fields(row, result = {}) click to toggle source
# File lib/drupal/file_managed.rb, line 27
def map_fields(row, result = {})
  result[:id] = id(row[:fid])
  result[:title] = row[:filename]
  result[:description] = row[:description]
  result[:url] = "#{config.drupal_base_url}/#{row[:uri].gsub(' ', '%20').gsub('public://','sites/default/files/')}"
  result
end