Class: Gitdocs::Initializer

Inherits:
Object
  • Object
show all
Defined in:
lib/gitdocs/initializer.rb

Class Method Summary collapse

Class Method Details

.databaseString

Returns:

  • (String)


52
53
54
# File 'lib/gitdocs/initializer.rb', line 52

def self.database
  @database ||= File.join(root_dirname, 'config.db')
end

.database=(value) ⇒ nil

Parameters:

  • value (nil, String)

Returns:

  • (nil)


58
59
60
61
# File 'lib/gitdocs/initializer.rb', line 58

def self.database=(value)
  return if value.nil?
  @database = value
end

.foregroundBoolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/gitdocs/initializer.rb', line 64

def self.foreground
  @foreground ||= false
end

.foreground=(value) ⇒ Object



68
69
70
71
# File 'lib/gitdocs/initializer.rb', line 68

def self.foreground=(value)
  return if value.nil?
  @foreground = value
end

.initialize_allnil

Returns:

  • (nil)


8
9
10
11
# File 'lib/gitdocs/initializer.rb', line 8

def self.initialize_all
  initialize_database
  initialize_old_paths
end

.initialize_databasenil

Returns:

  • (nil)


14
15
16
17
18
19
20
21
22
23
# File 'lib/gitdocs/initializer.rb', line 14

def self.initialize_database
  FileUtils.mkdir_p(root_dirname)
  ActiveRecord::Base.establish_connection(
    adapter: 'sqlite3',
    database: database
  )
  ActiveRecord::Migrator.migrate(
    File.expand_path('../migration', __FILE__)
  )
end

.initialize_old_pathsnil

Returns:

  • (nil)


26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/gitdocs/initializer.rb', line 26

def self.initialize_old_paths
  old_path_dirname = File.expand_path('paths', root_dirname)
  return unless File.exist?(old_path_dirname)

  File.read(old_path_dirname).split("\n").each do |path|
    begin
      Share.create_by_path!(path)
    rescue # rubocop:disable HandleExceptions
      # Nothing to do, because we want the process to keep going.
    end
  end
end

.root_dirnameString

Returns:

  • (String)


40
41
42
# File 'lib/gitdocs/initializer.rb', line 40

def self.root_dirname
  @root_dirname ||= File.expand_path('.gitdocs', ENV['HOME'])
end

.root_dirname=(value) ⇒ nil

Parameters:

  • value (nil, String)

Returns:

  • (nil)


46
47
48
49
# File 'lib/gitdocs/initializer.rb', line 46

def self.root_dirname=(value)
  return if value.nil?
  @root_dirname = value
end

.verboseBoolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/gitdocs/initializer.rb', line 74

def self.verbose
  @verbose ||= false
end

.verbose=(value) ⇒ Object

Parameters:

  • value (Boolean)


79
80
81
# File 'lib/gitdocs/initializer.rb', line 79

def self.verbose=(value)
  @verbose = !!value # rubocop:disable DoubleNegation
end