class Fiedl::Log::Log
Public Instance Methods
configuration(hash)
click to toggle source
# File lib/fiedl/log/log.rb, line 32 def configuration(hash) pp hash end
ensure_file(filename, options = {})
click to toggle source
Ensure that a certain file is present.
# File lib/fiedl/log/log.rb, line 72 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)
click to toggle source
# File lib/fiedl/log/log.rb, line 20 def error(text) self.write text.red end
filter(expression)
click to toggle source
# File lib/fiedl/log/log.rb, line 49 def filter(expression) filter_out expression end
filter_out(expression)
click to toggle source
# File lib/fiedl/log/log.rb, line 45 def filter_out(expression) @filter_out ||= [] @filter_out << expression end
head(text)
click to toggle source
# File lib/fiedl/log/log.rb, line 3 def head(text) info "" info "==========================================================".blue info text.blue info "==========================================================".blue end
info(text)
click to toggle source
# File lib/fiedl/log/log.rb, line 14 def info(text) self.write text end
p(text)
click to toggle source
# File lib/fiedl/log/log.rb, line 38 def p(text) @filter_out ||= [] @filter_out.each do |expression| text = text.gsub(expression, "[...]") end print text end
prompt(text)
click to toggle source
# File lib/fiedl/log/log.rb, line 26 def prompt(text) self.write "$ " + text.bold end
section(heading)
click to toggle source
# File lib/fiedl/log/log.rb, line 9 def section(heading) info "" info heading.blue info "----------------------------------------------------------".blue end
shell(command)
click to toggle source
Print commant, execute it and display result. See also: stackoverflow.com/a/10224650/2066546
# File lib/fiedl/log/log.rb, line 56 def shell(command) prompt command output = "" r, io = IO.pipe fork do system(command, out: io, err: :out) end io.close r.each_char{|c| print c; output += c} return output end
success(text)
click to toggle source
# File lib/fiedl/log/log.rb, line 17 def success(text) self.write text.green end
variable(variable, variable_name)
click to toggle source
# File lib/fiedl/log/log.rb, line 29 def variable(variable, variable_name) self.write "#{variable_name.to_s.blue} = #{variable}" end
warning(text)
click to toggle source
# File lib/fiedl/log/log.rb, line 23 def warning(text) self.write "Warning: ".yellow.bold + text.yellow end
write(text)
click to toggle source
# File lib/fiedl/log/log.rb, line 35 def write(text) self.p "#{text}\n" end