module Eitil module ExtendedResources RESOURCEFUL_ACTIONS = %i$ index new create show edit update destroy $ private def extended_resources(controller, **kwargs) all_args_to_ivars binding resources(controller, **resource_args) do extended_routes&.each { |route| send(route).call controller } yield if block_given? end end def resource_args duplicate = @kwargs.dup duplicate[:only] = resourceful_routes duplicate end def resourceful_routes @kwargs.dig(:only) - extended_routes end def extended_routes @kwargs.dig(:only) - RESOURCEFUL_ACTIONS end def new_route(verb, _method, action, scope) self.class.send :define_method, _method do -> (controller) { send(verb, _method, to: "#{controller}##{action}", on: scope) } end end end end ActionDispatch::Routing::Mapper.__send__ :include, Eitil::ExtendedResources