Rails best practices

Public
A code metric tool for rails codes, written in Ruby.
Icons/chart bar
Used 65 times
Created by
V Viktor Schmidt

Usage
RubyGems: https://rubygems.org/gems/rails_best_practices
Homepage: http://rails-bestpractices.com

$ rails_best_practices --test --features --output-file tmp/rails_best_practices_output.html -f html .
$ open tmp/rails_best_practices_output.html

Run this command in your Rails app directory in the terminal:

rails app:template LOCATION="https://railsbytes.com/script/x9Qsva"
Template Source

Review the code before running this template on your machine.

def do_bundle
  Bundler.with_unbundled_env { run "bundle install" }
end

def print_green(heredoc)
  puts set_color heredoc, :green
end

def do_commit
  git :init
  git add: "."
  Bundler.with_unbundled_env { git commit: " -m 'Add Rails best practices code metric tool' " }
end

def puts_usage
  say "\nUsage:"
  say "bin/rails_best_practices --test --features --output-file tmp/rails_best_practices_output.html -f html ."
  say "open tmp/rails_best_practices_output.html"
end

say "\nApplying Rails best practices code metric tool..."
inject_into_file 'Gemfile', after: 'group :development do' do
  <<-RUBY 

  # A code metric tool for rails codes, written in Ruby.
  gem "rails_best_practices", require: false
  RUBY
end

do_bundle

run "bundle binstubs rails_best_practices"
run "echo 'rails_best_practices_output.html' >> .gitignore"
run "bin/rails_best_practices --test --features --output-file tmp/rails_best_practices_output.html -f html ."
print_green "open tmp/rails_best_practices_output.html"

say "\nAdding documentation for developers..."
create_file "docs/quality_assurance.md", "# Source code quality assurance and best practices\n" unless File.exist? "docs/quality_assurance.md"
append_file "docs/quality_assurance.md" do
  <<~EOF 

  ## Rails best practices code metric tool

  Automatic [Rails best practices](https://rubygems.org/gems/rails_best_practices) code metric tool.

  ```bash
  bin/rails_best_practices --test --features --output-file tmp/rails_best_practices_output.html -f html .
  open tmp/rails_best_practices_output.html
  ```
  EOF
end

do_commit

print_green "\nAdded Rails best practices code metric tool successfully!"
puts_usage
Comments

Sign up or Login to leave a comment.