Module: LocalCI::Helper

Defined in:
lib/local_ci/helper.rb

Class Method Summary collapse

Class Method Details

.ci?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/local_ci/helper.rb', line 49

def self.ci?
  ENV.has_key?("CI")
end

.color?Boolean

Returns:

  • (Boolean)


3
4
5
# File 'lib/local_ci/helper.rb', line 3

def self.color?
  TTY::Color.support?
end

.human_duration(time_span) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/local_ci/helper.rb', line 30

def self.human_duration(time_span)
  seconds = time_span.dup
  minutes = (seconds / 60).to_i
  hours = minutes / 60

  seconds %= 60
  minutes %= 60

  if hours >= 1
    "#{hours}h #{minutes}m"

  elsif minutes >= 1
    "#{minutes}m #{seconds.floor}s"

  else
    "%.2fs" % seconds
  end
end

.local?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/local_ci/helper.rb', line 53

def self.local?
  !ci?
end

.loggerObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/local_ci/helper.rb', line 15

def self.logger
  return Logger.new($stdout) if ENV.has_key?("LOCAL_CI_LOG_TO_STDOUT")

  log_file = ci? ? $stdout : "logs/local_ci.log"
  log_file = ENV.fetch("LOCAL_CI_LOG_FILE", log_file)

  FileUtils.mkdir_p(File.dirname(log_file)) unless log_file == $stdout

  Logger.new(log_file)
end

.pastelObject



7
8
9
# File 'lib/local_ci/helper.rb', line 7

def self.pastel
  @pastel ||= Pastel.new(enabled: color?)
end

.runnerObject



11
12
13
# File 'lib/local_ci/helper.rb', line 11

def self.runner
  @runner ||= TTY::Command.new(color: color?, output: logger)
end

.taskize(heading) ⇒ Object



26
27
28
# File 'lib/local_ci/helper.rb', line 26

def self.taskize(heading)
  heading.downcase.gsub(/\s/, "_").gsub(/[^\w]/, "").to_sym
end