Sha256: 287088f6605f5501920f2315eeb037e4946d0ce8e0a3ba6fea0f7a7cb214cb52

Contents?: true

Size: 860 Bytes

Versions: 7

Compression:

Stored size: 860 Bytes

Contents

##
# Support the `:controller` and `:action` options.
#
# @example
#   get :admins, controller: :users
# @example
#   post :search, action: :index
module Rage::Router::DSLPlugins::ControllerActionOptions
  %i(get post put patch delete).each do |action_name|
    define_method(action_name) do |*args, **kwargs|
      if args.length == 1 && !kwargs.has_key?(:to) && (kwargs.has_key?(:controller) || kwargs.has_key?(:action))
        path = args[0]
        controller = kwargs.delete(:controller) || @controllers.last || raise(ArgumentError, "Could not derive the controller value from the route definitions")
        action = kwargs.delete(:action) || path.split("/").last
      end

      if controller && action
        kwargs[:to] = "#{controller}##{action}"
        super(path, **kwargs)
      else
        super(*args, **kwargs)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rage-rb-1.11.0 lib/rage/router/dsl_plugins/controller_action_options.rb
rage-rb-1.10.1 lib/rage/router/dsl_plugins/controller_action_options.rb
rage-rb-1.10.0 lib/rage/router/dsl_plugins/controller_action_options.rb
rage-rb-1.9.0 lib/rage/router/dsl_plugins/controller_action_options.rb
rage-rb-1.8.0 lib/rage/router/dsl_plugins/controller_action_options.rb
rage-rb-1.7.0 lib/rage/router/dsl_plugins/controller_action_options.rb
rage-rb-1.6.0 lib/rage/router/dsl_plugins/controller_action_options.rb