Sha256: 4b0881bbc2190580bca9a3bc1d6586c1a3abde94b6e1d124de7a3433565611ee

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

require 'fileutils'
require 'json'
require 'yaml'

require_relative 'tag'
require_relative 'vocabulary'
require_relative 'user'
require_relative 'content_type'
require_relative 'file_managed'

module Contentful
  module Exporter
    module Drupal
      class Export

        attr_reader :config, :boolean_columns

        def initialize(settings)
          @config = settings
          @boolean_columns = []
        end

        def save_data_as_json
          boolean_columns << YAML.load_file(config.config['drupal_boolean_columns']) if config.config['drupal_boolean_columns']
          tags
          vocabularies
          users
          content_types
          files
        end

        def write_json_to_file(path, data)
          File.open(path, 'w') do |file|
            file.write(JSON.pretty_generate(data))
          end
        end

        def create_directory(path)
          FileUtils.mkdir_p(path) unless File.directory?(path)
        end

        private

        def tags
          Tag.new(self, config).save_tags_as_json
        end

        def vocabularies
          Vocabulary.new(self, config).save_vocabularies_as_json
        end

        def users
          User.new(self, config).save_users_as_json
        end

        def files
          FileManaged.new(self, config).save_files_as_json
        end

        def content_types
          config.drupal_content_types.each do |content_type, schema|
            ContentType.new(self, config, content_type, schema).save_content_types_as_json
          end
        end

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
drupal-exporter-0.0.1 lib/drupal/export.rb