annotate

Set up annotate to annotate the models and routes
Icons/chart bar
Used 70 times
Created by
T TobiasBales

Usage

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

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

Review the code before running this template on your machine.

def create_bin(name, command = nil)
  create_file "bin/#{name}" do <<~EOF
    #!/usr/bin/env ruby
    APP_ROOT = File.expand_path('..', __dir__)
    Dir.chdir(APP_ROOT) do
      begin
        exec '#{command || name}'
      rescue Errno::ENOENT
        $stderr.puts "#{name} executable was not detected in the system."
        exit 1
      end
    end
  EOF
  end
  `chmod +x bin/#{name}`
end

gem_group :development do
  gem 'annotate'
end

Bundler.with_unbundled_env { run 'bundle install' }

initializer 'annotate.rb' do <<~RB
  require 'annotate'
  Annotate.set_defaults wrapper_open: 'rubocop:disable Layout/LineLength',
                        wrapper_close: 'rubocop:enable Layout/LineLength'
  RB
end

generate 'annotate:install'

create_bin 'annotate'

system('bundle exec rake annotate_models')
system('bundle exec rake annotate_routes')
Comments

Sign up or Login to leave a comment.