Class: ActionDispatch::Routing::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/support/action_dispatch/routing/mapper.rb

Overview

Re-open ActionDispatch::Routing::Mapper to add route helpers for Wallaby.

Instance Method Summary collapse

Instance Method Details

#wallaby_mount(options, &block) ⇒ Object

Mount Wallaby::Engine at given path. And prepend custom routes to Rails app if block is given.

Examples:

Mount Wallaby::Engine at a path

wallaby_mount at: '/admin'

Mount Wallaby::Engine and prepend custom routes

wallaby_mount at: '/super_admin' do
  resource :accounts
end
# the above code is the same as:
namespace :super_admin do
  resource :accounts
end
mount Wallaby::Engine, at: '/super_admin'

Parameters:

  • options (Hash)

Options Hash (options):



26
27
28
29
30
# File 'lib/support/action_dispatch/routing/mapper.rb', line 26

def wallaby_mount(options, &block)
  # define routes under namespace (e.g. `:admin`) before mounting the {Wallaby:Engine} (e.g. at `/admin`)
  namespace(options[:at][1..] || '', options.except(:at), &block) if block
  mount Wallaby::Engine, options.slice(:at, :as, :via)
end

#wresource(*resource_names, &block) ⇒ Object

Generate resourceful routes that works for Wallaby.

Examples:

To generate resourceful routes that works for Wallaby:

wresource :profile
# => same effect as
resource(
  :profile,
  path: ':resource',
  defaults: { resource: :profile, resources: :profiles },
  constraints: { resource: :profile, resources: :profiles }
)

Parameters:

  • resource_names (Array<String, Symbol>)

See Also:



66
67
68
69
70
71
72
# File 'lib/support/action_dispatch/routing/mapper.rb', line 66

def wresource(*resource_names, &block)
  options = Wallaby::Utils.clone resource_names.extract_options!
  resource_names.each do |resource_name|
    new_options = wallaby_resource_options_for resource_name, options
    resource resource_name, new_options, &block
  end
end

#wresources(*resource_names, &block) ⇒ Object

Generate resourceful routes that works for Wallaby.

Examples:

To generate resourceful routes that works for Wallaby:

wresources :postcodes
# => same effect as
resources(
  :postcodes,
  path: ':resources',
  defaults: { resources: :postcodes },
  constraints: { resources: :postcodes }
)

Parameters:

  • resource_names (Array<String, Symbol>)

See Also:



45
46
47
48
49
50
51
# File 'lib/support/action_dispatch/routing/mapper.rb', line 45

def wresources(*resource_names, &block)
  options = Wallaby::Utils.clone resource_names.extract_options!
  resource_names.each do |resource_name|
    new_options = wallaby_resources_options_for resource_name, options
    resources resource_name, new_options, &block
  end
end