Class: Takagi::CompositeRouter::MountedController

Inherits:
Struct
  • Object
show all
Defined in:
lib/takagi/composite_router.rb

Overview

Represents a mounted controller with its path and router

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#controller_classObject

Returns the value of attribute controller_class

Returns:

  • (Object)

    the current value of controller_class



17
18
19
# File 'lib/takagi/composite_router.rb', line 17

def controller_class
  @controller_class
end

#mount_pathObject

Returns the value of attribute mount_path

Returns:

  • (Object)

    the current value of mount_path



17
18
19
# File 'lib/takagi/composite_router.rb', line 17

def mount_path
  @mount_path
end

#nested_controllersObject

Returns the value of attribute nested_controllers

Returns:

  • (Object)

    the current value of nested_controllers



17
18
19
# File 'lib/takagi/composite_router.rb', line 17

def nested_controllers
  @nested_controllers
end

#routerObject

Returns the value of attribute router

Returns:

  • (Object)

    the current value of router



17
18
19
# File 'lib/takagi/composite_router.rb', line 17

def router
  @router
end

Instance Method Details

#handles?(path) ⇒ Boolean

Check if this mount handles the given path

Parameters:

  • path (String)

    Request path

Returns:

  • (Boolean)

    true if path starts with mount_path



22
23
24
# File 'lib/takagi/composite_router.rb', line 22

def handles?(path)
  path.start_with?(mount_path)
end

#relative_path(path) ⇒ String

Strip the mount prefix from a path

Parameters:

  • path (String)

    Full request path

Returns:

  • (String)

    Path with mount prefix removed



30
31
32
33
34
# File 'lib/takagi/composite_router.rb', line 30

def relative_path(path)
  return path if mount_path == '/'

  path.sub(/^#{Regexp.escape(mount_path)}/, '') || '/'
end