Module: RedmineInstaller::Utils

Constant Summary collapse

PROGRESSBAR_FORMAT =
':elapsed [:bar] :percent'

Instance Method Summary collapse

Instance Method Details

#class_nameObject



6
7
8
# File 'lib/redmine-installer/utils.rb', line 6

def class_name
  self.class.name.split('::').last
end

#create_dir(dir) ⇒ Object

Try create a dir When mkdir raise an error (permission problem) method ask user if wants exist or try again



41
42
43
44
45
46
47
48
49
# File 'lib/redmine-installer/utils.rb', line 41

def create_dir(dir)
  FileUtils.mkdir_p(dir)
rescue
  if prompt.yes?("Dir #{dir} doesn't exist and can't be created. Try again?", default: true)
    create_dir(dir)
  else
    error('Dir creating was aborted by user.')
  end
end

#env_userObject



35
36
37
# File 'lib/redmine-installer/utils.rb', line 35

def env_user
  ENV['USER'] || ENV['USERNAME']
end

#error(message) ⇒ Object



56
57
58
# File 'lib/redmine-installer/utils.rb', line 56

def error(message)
  raise RedmineInstaller::Error, message
end

#loggerObject



10
11
12
# File 'lib/redmine-installer/utils.rb', line 10

def logger
  RedmineInstaller.logger
end

#ok(title) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/redmine-installer/utils.rb', line 26

def ok(title)
  print "#{title} ... "
  yield
  puts pastel.green('OK')
rescue => e
  puts pastel.red('FAIL')
  raise
end

#pastelObject



18
19
20
# File 'lib/redmine-installer/utils.rb', line 18

def pastel
  RedmineInstaller.pastel
end


51
52
53
54
# File 'lib/redmine-installer/utils.rb', line 51

def print_title(title)
  puts
  puts pastel.white.on_black(title)
end

#promptObject



14
15
16
# File 'lib/redmine-installer/utils.rb', line 14

def prompt
  RedmineInstaller.prompt
end

#run_command(cmd, title = nil) ⇒ Object



22
23
24
# File 'lib/redmine-installer/utils.rb', line 22

def run_command(cmd, title=nil)
  RedmineInstaller::Command.new(cmd, title: title).run
end