Module: Selective::Ruby::Core::Helper

Included in:
Controller, FileCorrelator
Defined in:
lib/selective/ruby/core/helper.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/selective/ruby/core/helper.rb', line 62

def self.banner
  $selective_banner_displayed = true
  <<~BANNER
     ____       _           _   _
    / ___|  ___| | ___  ___| |_(_)_   _____
    \\___ \\ / _ \\ |/ _ \\/ __| __| \\ \\ / / _ \\
     ___) |  __/ |  __/ (__| |_| |\\ V /  __/
    |____/ \\___|_|\\___|\\___|\\__|_| \\_/ \\___|
    ________________________________________
  BANNER
end

Instance Method Details



58
59
60
# File 'lib/selective/ruby/core/helper.rb', line 58

def banner
  Helper.banner
end


47
48
49
50
51
52
# File 'lib/selective/ruby/core/helper.rb', line 47

def print_notice(message)
  puts_indented <<~TEXT
    #{banner unless $selective_banner_displayed}
    #{message}
  TEXT
end


39
40
41
42
43
44
45
# File 'lib/selective/ruby/core/helper.rb', line 39

def print_warning(message)
  puts_indented <<~TEXT
    \e[33m
    #{message}
    \e[0m
  TEXT
end

#puts_indented(text) ⇒ Object



54
55
56
# File 'lib/selective/ruby/core/helper.rb', line 54

def puts_indented(text)
  puts text.gsub(/^/, "  ")
end

#safe_filename(filename) ⇒ Object



5
6
7
8
9
10
# File 'lib/selective/ruby/core/helper.rb', line 5

def safe_filename(filename)
  filename
    .gsub(/[\/\\:*?"<>|\n\r]+/, '_')
    .gsub(/^\.+|\.+$/, '')
    .strip[0, 255]
end

#with_error_handling(include_header: true) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/selective/ruby/core/helper.rb', line 12

def with_error_handling(include_header: true)
  yield
rescue => e
  raise e if debug?
  header = <<~TEXT
    An error occurred. Please rerun with --debug
    and contact support at https://selective.ci/support
  TEXT

  unless $selective_banner_displayed
    header = <<~TEXT
      #{banner}

      #{header}
    TEXT
  end

  puts_indented <<~TEXT
    \e[31m
    #{header if include_header}
    #{e.message}
    \e[0m
  TEXT

  exit 1
end