module ActionDispatch::Routing::Mapper::Resources

def arvm_resource(resource_name, options = {}, &block)

def arvm_resource(resource_name, options = {}, &block)
  except             = options.delete(:except) { [] }
  add_shallow_routes = options.delete(:add_shallow_routes) { true }
  only_routes = []
  is_shallow = false
  resource resource_name, shallow: true, only: only_routes, **options do
    is_shallow = shallow_nesting_depth > 1
    instance_eval(&block) if block_given?
    name_route = { as: '' } # Only one route may take the name
    if is_shallow
      post('',   action: :create_associated,  **name_route.extract!(:as)) unless except.include?(:create)
      get('',    action: :show_associated,    **name_route.extract!(:as)) unless except.include?(:show)
      delete('', action: :destroy_associated, **name_route.extract!(:as)) unless except.include?(:destroy)
    else
      post('',   action: :create,  **name_route.extract!(:as)) unless except.include?(:create)
      get('',    action: :show,    **name_route.extract!(:as)) unless except.include?(:show)
      delete('', action: :destroy, **name_route.extract!(:as)) unless except.include?(:destroy)
    end
  end
  # singularly nested resources provide collection accessors at the top level
  if is_shallow && add_shallow_routes
    resources resource_name.to_s.pluralize, shallow: true, only: [:show, :destroy] - except do
      shallow_scope do
        collection do
          name_route = { as: '' } # Only one route may take the name
          post('', action: :create, **name_route.extract!(:as)) unless except.include?(:create)
          get('',  action: :index,  **name_route.extract!(:as)) unless except.include?(:index)
        end
      end
    end
  end
end