annotate_models icon indicating copy to clipboard operation
annotate_models copied to clipboard

Use `rails routes` instead of `rake routes`, minimum rails is now 5.0

Open Vasfed opened this issue 5 years ago • 11 comments

This fixes https://github.com/ctran/annotate_models/issues/696 Major version bump is required because of minimum rails >= 5.0

Vasfed avatar Nov 24 '20 19:11 Vasfed

Doesn't work for me on Ruby 2.6.6 and Rails 6.1.

rake aborted!
Don't know how to build task 'routes' (See the list of available tasks with `rake --tasks`)
/Users/heaven/.rvm/gems/ruby-2.6.6@lively-letters/bin/ruby_executable_hooks:22:in `eval'
/Users/heaven/.rvm/gems/ruby-2.6.6@lively-letters/bin/ruby_executable_hooks:22:in `<main>'
(See full trace by running task with --trace)
config/routes.rb unchanged.

heaven avatar Jan 21 '21 11:01 heaven

this one works with rails 6.1.0.rc

saiqulhaq avatar Jan 21 '21 15:01 saiqulhaq

Are there any plans to cut a release with this PR? annotate_routes doesn't work on Rails 6.2.

stouset avatar Mar 07 '21 02:03 stouset

Bumping again as I have my gemfile pegged to @Vasfed 's fork on the rails6_warning branch.

katelovescode avatar Mar 20 '21 21:03 katelovescode

@ctran please

8e4487c780adcc95ce856b305219c442

skv-headless avatar Mar 30 '22 14:03 skv-headless

Rebased onto current develop, test seem to fail because of run order and not the changes

Vasfed avatar Aug 01 '22 16:08 Vasfed

This works great for me! Not sure why the CI is failing. I also tried replacing rake routes with rails routes, and it works fine for me.

I prefer not to add forked gems to my Gemfile since they don't get updated by dependabot. So I just added a monkey patch for this method to lib/monkey_patches/annotate_routes.rb:

# frozen_string_literal: true

if Rails.env.development?
  if Annotate.version != '3.2.0'
    raise "annotate has been updated to version #{Annotate.version}! " \
      "Check if the 'rails routes' patch is still needed, or if this PR has been merged: " \
      'https://github.com/ctran/annotate_models/pull/843'
  end

  module AnnotateRoutes
    class HeaderGenerator
      class << self
        private

        # UPDATE: Changed `rake routes` to `rails routes`
        def routes_map(options)
          result = `rails routes`.chomp("\n").split(/\n/, -1)

          # In old versions of Rake, the first line of output was the cwd.  Not so
          # much in newer ones.  We ditch that line if it exists, and if not, we
          # keep the line around.
          result.shift if result.first =~ %r{^\(in /}

          ignore_routes = options[:ignore_routes]
          regexp_for_ignoring_routes = ignore_routes ? /#{ignore_routes}/ : nil

          # Skip routes which match given regex
          # Note: it matches the complete line (route_name, path, controller/action)
          if regexp_for_ignoring_routes
            result.reject { |line| line =~ regexp_for_ignoring_routes }
          else
            result
          end
        end
      end
    end
  end
end

ndbroadbent avatar Nov 24 '22 02:11 ndbroadbent

Route annotation is broken until this is addressed @ctran ! How can the community help maintain this library? I've helped in the past (long, long ago, in a galaxy far away) and would be happy to help out again! I love this tool!

pboling avatar Dec 08 '22 04:12 pboling

I need help getting CI to work if you can spare some time. I was attempting to set up gitpod env but ran into few issues and haven't had time to continue.

ctran avatar Dec 09 '22 17:12 ctran

I was able to add a task that solved this for me:

lib/tasks.routes.rake

task :routes do
  puts `bin/rails routes`
end

This injects the rails routes behavior into the rake implementation that the gem is currently looking for.

CoderMiguel avatar Jun 01 '23 21:06 CoderMiguel

@ctran looks like the CI issues have been resolved now so hopefully this is good to go - is there anything else that could be done to help you with shipping this?

G-Rath avatar Jan 01 '24 21:01 G-Rath