class Contentful::Exporter::Drupal::ContentType
Attributes
config[R]
exporter[R]
schema[R]
type[R]
Public Class Methods
new(exporter, config, type, schema)
click to toggle source
# File lib/drupal/content_type.rb, line 8 def initialize(exporter, config, type, schema) @exporter = exporter @config = config @type = type @schema = schema end
Public Instance Methods
save_content_types_as_json()
click to toggle source
# File lib/drupal/content_type.rb, line 15 def save_content_types_as_json exporter.create_directory("#{config.entries_dir}/#{type}") config.db[:node].where(type: type).each do |content_row| extract_data(content_row) end end
Private Instance Methods
boolean_column?(column_name)
click to toggle source
# File lib/drupal/content_type.rb, line 140 def boolean_column?(column_name) exporter.boolean_columns && exporter.boolean_columns.flatten.include?(column_name) ? true : false end
convert_boolean_value(value)
click to toggle source
# File lib/drupal/content_type.rb, line 144 def convert_boolean_value(value) value.nil? ? nil : (value == 1 ? true : false) end
convert_type_value(value, column_name)
click to toggle source
# File lib/drupal/content_type.rb, line 130 def convert_type_value(value, column_name) if value.is_a?(BigDecimal) value.to_f elsif boolean_column?(column_name) convert_boolean_value(value) else value end end
created_at(timestamp)
click to toggle source
# File lib/drupal/content_type.rb, line 126 def created_at(timestamp) Time.at(timestamp).to_datetime end
extract_data(content_row)
click to toggle source
# File lib/drupal/content_type.rb, line 24 def extract_data(content_row) puts "Saving #{type} - id: #{content_row[:nid]}" db_object = map_fields(content_row) exporter.write_json_to_file("#{config.entries_dir}/#{type}/#{db_object[:id]}.json", db_object) end
field_name(table_name)
click to toggle source
# File lib/drupal/content_type.rb, line 122 def field_name(table_name) "#{table_name}_value".to_sym end
file_id(file_id)
click to toggle source
# File lib/drupal/content_type.rb, line 92 def file_id(file_id) config.db[:file_managed].where(fid: file_id).first[:fid] end
get_file_id(related_row, table_name)
click to toggle source
# File lib/drupal/content_type.rb, line 85 def get_file_id(related_row, table_name) file_key = "#{table_name}_fid".to_sym file_id = related_row.first[file_key] file_asset_id = file_id(file_id) link_asset_to_content_type(file_asset_id) end
id(content_id)
click to toggle source
# File lib/drupal/content_type.rb, line 36 def id(content_id) "#{type}_#{content_id}" end
link_asset_to_content_type(file_asset_id)
click to toggle source
# File lib/drupal/content_type.rb, line 100 def link_asset_to_content_type(file_asset_id) {type: 'File', id: "file_#{file_asset_id}"} end
map_fields(row, result = {})
click to toggle source
# File lib/drupal/content_type.rb, line 30 def map_fields(row, result = {}) result.merge!(set_default_data(row)) result.merge!(find_related_data(row)) result end
respond_to_file?(related_row, table_name)
click to toggle source
# File lib/drupal/content_type.rb, line 80 def respond_to_file?(related_row, table_name) file_id = "#{table_name}_fid".to_sym (related_row.present? && related_row.first[file_id]) ? true : false end
set_default_data(row, result = {})
click to toggle source
# File lib/drupal/content_type.rb, line 55 def set_default_data(row, result = {}) result[:id] = id(row[:nid]) result[:title] = row[:title] result[:author] = author(row[:uid]) result[:tags] = tags(row[:nid]) unless tags(row[:nid]).empty? result[:created_at] = created_at(row[:created]) result end