Module: CommandLine::Tools

Extended by:
Tools
Included in:
Tools
Defined in:
lib/cli/tools.rb

Instance Method Summary collapse

Instance Method Details

#install_rake_tasks(install_type = :rails) ⇒ Object

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.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/cli/tools.rb', line 34

def install_rake_tasks(install_type = :rails)
  if install_type.to_sym == :rails
    require 'fileutils'
    if File.directory?('./lib/tasks/')
      task_file = File.expand_path('../../tasks/request_log_analyzer.rake', File.dirname(__FILE__))
      FileUtils.copy(task_file, './lib/tasks/request_log_analyze.rake')
      puts 'Installed rake tasks.'
      puts 'To use, run: rake rla:report'
    else
      puts 'Cannot find /lib/tasks folder. Are you in your Rails directory?'
      puts 'Installation aborted.'
    end
  else
    fail "Cannot perform this install type! (#{install_type})"
  end
end

#terminal_width(default_width = 81, out = STDOUT) ⇒ Object

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



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cli/tools.rb', line 8

def terminal_width(default_width = 81, out = STDOUT)
  tiocgwinsz = 0x5413
  data = [0, 0, 0, 0].pack('SSSS')
  if !RUBY_PLATFORM.include?('java') && out.ioctl(tiocgwinsz, data) >= 0 # JRuby crashes on ioctl
    _, cols, _, _ = data.unpack('SSSS')
    fail unless cols > 0
    cols
  else
    fail
  end
rescue
  begin
    IO.popen('stty -a 2>&1') do |pipe|
      column_line = pipe.find { |line| /(\d+) columns/ =~ line }
      fail unless column_line
      Regexp.last_match[1].to_i
    end
  rescue
    default_width
  end
end