Class: Thoth::Importer
- Inherits:
-
Object
show all
- Includes:
- Innate::Traited
- Defined in:
- lib/thoth/importer.rb
Class Method Summary
collapse
Class Method Details
.after_import(&block) ⇒ Object
35
|
# File 'lib/thoth/importer.rb', line 35
def after_import(&block) trait(:after => block); end
|
.before_import(&block) ⇒ Object
36
|
# File 'lib/thoth/importer.rb', line 36
def before_import(&block) trait(:before => block); end
|
37
|
# File 'lib/thoth/importer.rb', line 37
def (&block) trait(:comments => block); end
|
38
|
# File 'lib/thoth/importer.rb', line 38
def import_media(&block) trait(:media => block); end
|
.import_pages(&block) ⇒ Object
39
|
# File 'lib/thoth/importer.rb', line 39
def import_pages(&block) trait(:pages => block); end
|
.import_posts(&block) ⇒ Object
40
|
# File 'lib/thoth/importer.rb', line 40
def import_posts(&block) trait(:posts => block); end
|
41
|
# File 'lib/thoth/importer.rb', line 41
def import_tags(&block) trait(:tags => block); end
|
.load_importer(name) ⇒ Object
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/thoth/importer.rb', line 43
def load_importer(name)
importer = name.to_s.downcase.strip.gsub(/importer$/, '')
files = Dir["{#{File.join(HOME_DIR, 'importer')},#{File.join(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 ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/thoth/importer.rb', line 54
def run
Ramaze::Log.loggers = []
begin
Thoth.init_thoth
rescue => e
abort("Error: #{e}")
end
[Comment, Media, Page, Post].each do |klass|
klass.class_eval('def before_create; end')
klass.class_eval('def before_save; end')
end
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)?/i
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
|