Q:

How to add method that can be used in routes to Gem?

I am building a gem for Rails and would like to make a method available to the routes of the Rails app that uses my gem.
Basically, I want whoever uses my gem to be able to say
websockets_for :messages

which will create a bunch of routes for them. I am unsure where to define that method so that it's available in the routes file.
The method looks something like this:
def websockets_for(resources)
  get "/#{resources}", to: "#{resources}#index", as: resources
end

It's basically a helper method I want to make available to generate routes.
I have only found this: https://www.pgrs.net/2007/09/28/add-routes-with-a-rails-plugin-or-gem/
It seems pretty old (from 2007), and I don't think ActionController::Routing is still being used. What's the best way to do this?

A:

Based on Frederick Cheung's comment, I was able to implement this:
require 'action_dispatch/routing'
require 'active_support/concern'

module ActionDispatch::Routing
  class Mapper
    def websockets_for(resource, &block)
      # here, use methods like get, match, etc
      get "/#{resources}", to: "#{resources}#index", as: resources
    end
  end
end

It works! Now, the method websockets_for is available in a Rails app's routes if the gem is installed.

