Class: Tractive::Main

Inherits:
Object
  • Object
show all
Defined in:
lib/tractive/main.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Main

Returns a new instance of Main.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/tractive/main.rb', line 5

def initialize(opts)
  verify_options!(opts)

  @opts = opts
  @cfg  = YAML.load_file(@opts[:config])

  Tractive::Utilities.setup_logger(output_stream: @opts[:logfile] || $stderr, verbose: @opts[:verbose])

  verify_config!(@cfg, @opts)

  @cfg["github"] ||= {}
  @cfg["github"]["token"] = @opts["git-token"] if @opts["git-token"]

  GithubApi::GraphQlClient.add_constants(@cfg["github"]["token"]) unless @opts[:info]

  @db = Tractive::Utilities.setup_db!(@opts["trac-database-path"] || @cfg["trac"]["database"])
rescue Sequel::DatabaseConnectionError, Sequel::AdapterNotFound, URI::InvalidURIError, Sequel::DatabaseError => e
  $logger.error e.message
  exit 1
rescue StandardError => e
  warn_and_exit(e.message, 1)
end

Instance Method Details

#create_attachment_exporter_scriptObject



58
59
60
# File 'lib/tractive/main.rb', line 58

def create_attachment_exporter_script
  Tractive::AttachmentExporter.new(@cfg, @db).generate_script
end

#export_attachmentsObject



54
55
56
# File 'lib/tractive/main.rb', line 54

def export_attachments
  Tractive::AttachmentExporter.new(@cfg, @db).export
end

#infoObject



50
51
52
# File 'lib/tractive/main.rb', line 50

def info
  Tractive::Info.new.print
end

#migrateObject



42
43
44
# File 'lib/tractive/main.rb', line 42

def migrate
  Migrator::Engine.new(opts: @opts, cfg: @cfg, db: @db).migrate
end

#migrate_wikisObject



46
47
48
# File 'lib/tractive/main.rb', line 46

def migrate_wikis
  Migrator::Wikis::MigrateFromDb.new(opts: @opts, cfg: @cfg).migrate_wikis
end

#runObject



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/tractive/main.rb', line 28

def run
  if @opts[:info]
    info
  elsif @opts[:attachmentexporter]
    create_attachment_exporter_script
  elsif @opts[:exportattachments]
    export_attachments
  elsif @opts[:generaterevmap]
    generate_revmap_file
  else
    migrate
  end
end