Class: Thoth::Importer

### Home Classes Methods

### In Files

- lib/thoth/importer.rb

### Parent

Object

### Methods

- ::after_import
- ::before_import
- ::import_comments
- ::import_media
- ::import_pages
- ::import_posts
- ::import_tags
- ::load_importer
- ::run

### Files

- robots.txt

### Class/Module Index

Quicksearch

- Thoth
- Thoth::AdminController
- Thoth::ArchiveController
- Thoth::Comment
- Thoth::CommentApiController
- Thoth::CommentController
- Thoth::Config
- Thoth::Error
- Thoth::Importer
- Thoth::MainController
- Thoth::Media
- Thoth::MediaController
- Thoth::MinifyController
- Thoth::Page
- Thoth::PageApiController
- Thoth::PageController
- Thoth::Pager
- Thoth::Plugin
- Thoth::Plugin::Delicious
- Thoth::Plugin::Flickr
- Thoth::Plugin::Tags
- Thoth::Plugin::Twitter
- Thoth::Post
- Thoth::PostApiController
- Thoth::PostController
- Thoth::SchemaError
- Thoth::SearchController
- Thoth::Tag
- Thoth::TagApiController
- Thoth::TagController
- Thoth::TagsPostsMap
- Ramaze
- Ramaze::Dispatcher
- Ramaze::Dispatcher::File
- Ramaze::Helper
- Ramaze::Helper::Admin
- Ramaze::Helper::Cookie
- Ramaze::Helper::Error
- Ramaze::Helper::Pagination
- Ramaze::Helper::Sanitize
- Ramaze::Helper::Wiki
- Ramaze::Helper::Ysearch
- Ramaze::Helper::Ysearch::SearchError
- AddMediaSize
- CreateSchema
- PantsImporter
- PoseidonImporter

No matching classes.

# Thoth::Importer

### Public Class Methods

after_import(&block) click to toggle source

    # File lib/thoth/importer.rb, line 33
    def after_import(&block)    trait[:after]    = block; end

before_import(&block) click to toggle source

    # File lib/thoth/importer.rb, line 34
    def before_import(&block)   trait[:before]   = block; end

import_comments(&block) click to toggle source

    # File lib/thoth/importer.rb, line 35
    def import_comments(&block) trait[:comments] = block; end

import_media(&block) click to toggle source

    # File lib/thoth/importer.rb, line 36
    def import_media(&block)    trait[:media]    = block; end

import_pages(&block) click to toggle source

    # File lib/thoth/importer.rb, line 37
    def import_pages(&block)    trait[:pages]    = block; end

import_posts(&block) click to toggle source

    # File lib/thoth/importer.rb, line 38
    def import_posts(&block)    trait[:posts]    = block; end

import_tags(&block) click to toggle source

    # File lib/thoth/importer.rb, line 39
    def import_tags(&block)     trait[:tags]     = block; end

load_importer(name) click to toggle source

    # File lib/thoth/importer.rb, line 41
    def load_importer(name)
      importer = name.to_s.downcase.strip.gsub(/importer$/, '')
      files    = Dir["{#{HOME_DIR/:importer},#{LIB_DIR/:importer},#{$:.join(',')}}/#{importer}.rb"]

      unless (files.any? && require(files.first)) || require(importer)
        raise LoadError, "Importer #{name} not found"
      end

      Kernel.const_get("#{importer.capitalize}Importer")
    end

run() click to toggle source

    # File lib/thoth/importer.rb, line 52
    def run
      # Bootstrap.
      Ramaze::Log.loggers = []

      begin
        Thoth.init_thoth
      rescue => e
        abort("Error: #{e}")
      end

      # Disable model hooks.
      [Comment, Media, Page, Post].each do |klass|
        klass.class_eval('def before_create; end')
        klass.class_eval('def before_save; end')
      end

      # Confirm that the user really wants to blow away their database.
      puts "WARNING: Your existing Thoth database will be completely erased to make way"
      puts "for the imported content. Are you sure you want to continue? (y/n) "
      print "> "

      exit unless STDIN.gets.strip =~ /^y(?:es)?/
      puts

      trait[:before].call if trait[:before]

      if trait[:pages]
        puts 'Importing pages...'

        Thoth.db.transaction do
          Page.delete
          trait[:pages].call
        end
      end

      if trait[:posts]
        puts 'Importing blog posts...'

        Thoth.db.transaction do
          Post.delete
          trait[:posts].call
        end
      end

      if trait[:tags]
        puts 'Importing tags...'

        Thoth.db.transaction do
          Tag.delete
          TagsPostsMap.delete
          trait[:tags].call
        end
      end

      if trait[:comments]
        puts 'Importing comments...'

        Thoth.db.transaction do
          Comment.delete
          trait[:comments].call
        end
      end

      if trait[:media]
        puts 'Importing media...'

        Thoth.db.transaction do
          Media.delete
          trait[:media].call
        end
      end

      trait[:after].call if trait[:after]
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.