Class: Fiedl::Log::Log

Inherits:
Object
  • Object
show all
Defined in:
lib/fiedl/log/log.rb

Instance Method Summary collapse

Instance Method Details

#configuration(hash) ⇒ Object



34
35
36
# File 'lib/fiedl/log/log.rb', line 34

def configuration(hash)
  pp hash
end

#ensure_file(filename, options = {}) ⇒ Object

Ensure that a certain file is present.



87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/fiedl/log/log.rb', line 87

def ensure_file(filename, options = {})
  if File.exists?(filename)
    log.success "File: #{filename}"
  else
    log.error "Something went wrong. File #{filename} is missing."
    if options[:show_log]
      log.section "Last log"
      shell "tail -n 20 #{options[:show_log]}"
    end
    raise "File is missing."
  end
end

#error(text) ⇒ Object



22
23
24
# File 'lib/fiedl/log/log.rb', line 22

def error(text)
  self.write text.red
end

#filter(expression) ⇒ Object



51
52
53
# File 'lib/fiedl/log/log.rb', line 51

def filter(expression)
  filter_out expression
end

#filter_out(expression) ⇒ Object



47
48
49
50
# File 'lib/fiedl/log/log.rb', line 47

def filter_out(expression)
  @filter_out ||= []
  @filter_out << expression
end

#head(text) ⇒ Object



5
6
7
8
9
10
# File 'lib/fiedl/log/log.rb', line 5

def head(text)
  info ""
  info "==========================================================".blue
  info text.blue
  info "==========================================================".blue
end

#info(text) ⇒ Object



16
17
18
# File 'lib/fiedl/log/log.rb', line 16

def info(text)
  self.write text
end

#p(text) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/fiedl/log/log.rb', line 40

def p(text)
  @filter_out ||= []
  @filter_out.each do |expression|
    text = text.gsub(expression, "[...]")
  end
  print text
end

#prompt(text) ⇒ Object



28
29
30
# File 'lib/fiedl/log/log.rb', line 28

def prompt(text)
  self.write "$ " + text.bold
end

#raise(text) ⇒ Object



55
56
57
58
# File 'lib/fiedl/log/log.rb', line 55

def raise(text)
  self.error(text.bold)
  super(text)
end

#return_codeObject



81
82
83
# File 'lib/fiedl/log/log.rb', line 81

def return_code
  @return_code
end

#section(heading) ⇒ Object



11
12
13
14
15
# File 'lib/fiedl/log/log.rb', line 11

def section(heading)
  info ""
  info heading.blue
  info "----------------------------------------------------------".blue
end

#shell(command, verbose: true) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/fiedl/log/log.rb', line 68

def shell(command, verbose: true)
  prompt command if verbose

  file = Tempfile.new("fiedl-log")
  @return_code = system "script -q #{file.path} #{command}"
  output = file.read

  return output
ensure
  file.close
  file.unlink
end

#success(text) ⇒ Object



19
20
21
# File 'lib/fiedl/log/log.rb', line 19

def success(text)
  self.write text.green
end

#variable(variable, variable_name) ⇒ Object



31
32
33
# File 'lib/fiedl/log/log.rb', line 31

def variable(variable, variable_name)
  self.write "#{variable_name.to_s.blue} = #{variable}"
end

#warning(text) ⇒ Object



25
26
27
# File 'lib/fiedl/log/log.rb', line 25

def warning(text)
  self.write "Warning: ".yellow.bold + text.yellow
end

#write(text) ⇒ Object



37
38
39
# File 'lib/fiedl/log/log.rb', line 37

def write(text)
  self.p "#{text}\n"
end