module CommandLine::Tools

Public Instance Methods

install_rake_tasks(install_type = :rails) click to toggle source

Copies request-log-analyzer analyzer rake tasks into the /lib/tasks folder of a project, for easy access and environment integration. install_type Type of project to install into. Defaults to :rails. Raises if it cannot find the project folder or if the install_type is now known.

   # File lib/cli/tools.rb
34 def install_rake_tasks(install_type = :rails)
35   if install_type.to_sym == :rails
36     require 'fileutils'
37     if File.directory?('./lib/tasks/')
38       task_file = File.expand_path('../../tasks/request_log_analyzer.rake', File.dirname(__FILE__))
39       FileUtils.copy(task_file, './lib/tasks/request_log_analyze.rake')
40       puts 'Installed rake tasks.'
41       puts 'To use, run: rake rla:report'
42     else
43       puts 'Cannot find /lib/tasks folder. Are you in your Rails directory?'
44       puts 'Installation aborted.'
45     end
46   else
47     fail "Cannot perform this install type! (#{install_type})"
48   end
49 end
terminal_width(default_width = 81, out = STDOUT) click to toggle source

Try to determine the terminal with. If it is not possible to to so, it returns the default_width. default_width Defaults to 81

   # File lib/cli/tools.rb
 8 def terminal_width(default_width = 81, out = STDOUT)
 9   tiocgwinsz = 0x5413
10   data = [0, 0, 0, 0].pack('SSSS')
11   if !RUBY_PLATFORM.include?('java') && out.ioctl(tiocgwinsz, data) >= 0 # JRuby crashes on ioctl
12     _, cols, _, _ = data.unpack('SSSS')
13     fail unless cols > 0
14     cols
15   else
16     fail
17   end
18 rescue
19   begin
20     IO.popen('stty -a 2>&1') do |pipe|
21       column_line = pipe.find { |line| /(\d+) columns/ =~ line }
22       fail unless column_line
23       Regexp.last_match[1].to_i
24     end
25   rescue
26     default_width
27   end
28 end