Example code:
$ brakeman -o raport.html
$ brakeman --skip-files file1,file2 // exclude files
$ brakeman --compare old_report.json
Example code:
$ rails_best_practices -f html .
$ rails_best_practices -e "db/migrate,vendor" . // exclude folders
Example code:
require 'ruby-prof'�
# Profile the code
RubyProf.start
[code to profile]
RubyProf.pause
[other code]
RubyProf.resume
[code to profile]
results = RubyProf.stop
File.open "#{Rails.root}/profile-graph.html", 'w' do |file|
RubyProf::GraphHtmlPrinter.new(results).print(file)
end
File.open "#{Rails.root}/profile-flat.txt", 'w' do |file|
RubyProf::FlatPrinter.new(results).print(file)
end
File.open "#{Rails.root}/profile-tree.prof", 'w' do |file|
RubyProf::CallTreePrinter.new(results).print(file)
end
Simple example code:
require 'benchmark'
puts Benchmark.measure { "a"*1_000_000_000 }
Code with block and custom definitions:
require 'benchmark'
include Benchmark # we need the CAPTION and FORMAT constants
n = 5000000
Benchmark.benchmark(CAPTION, 7, FORMAT, ">total:", ">avg:") do |x|
tf = x.report("for:") { for i in 1..n; a = "1"; end }
tt = x.report("times:") { n.times do ; a = "1"; end }
tu = x.report("upto:") { 1.upto(n) do ; a = "1"; end }
[tf+tt+tu, (tf+tt+tu)/3]
end
- Github
Example code:
$ rubocop --format simple
$ rubocop -R --format html -o rubocop.html
Example code:
$ gem install flog
$ gem install flay
$ flog .
$ flay .
Ruby >= 2.0 For Ruby < 2.0 use debugger gem
Example code:
...
byebug
...
RubyCritic is a gem that wraps around static analysis gems such as Reek, Flay and Flog to provide a quality report of your Ruby code.
Example code:
$ rubycritic app lib/foo.rb
$ rubycritic --help
Rbkit is a profiler built with ease of use in mind. Currently it supports memory profiling (CPU profiling in works) of Ruby applications.
Example code:
$ require 'rbkit'
$ Rbkit.start_profiling
ruby-lint is a static code analysis tool for Ruby. It is inspired by tools such as jshint, flake8 and similar tools. ruby-lint primarily focuses on logic related errors such as the use of non existing variables instead of focusing on semantics (e.g. the amount of characters per line).
Example code:
$ gem install ruby-lint
$ ruby-lint file1.rb file2.rb