Object
# File lib/thoth/importer.rb, line 33 def after_import(&block) trait[:after] = block; end
# File lib/thoth/importer.rb, line 34 def before_import(&block) trait[:before] = block; end
# File lib/thoth/importer.rb, line 35 def import_comments(&block) trait[:comments] = block; end
# File lib/thoth/importer.rb, line 36 def import_media(&block) trait[:media] = block; end
# File lib/thoth/importer.rb, line 37 def import_pages(&block) trait[:pages] = block; end
# File lib/thoth/importer.rb, line 38 def import_posts(&block) trait[:posts] = block; end
# 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
# 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
Generated with the Darkfish Rdoc Generator 2.