Class: JSRailsRoutes::Route

Inherits:
Object
  • Object
show all
Defined in:
lib/js_rails_routes/route.rb

Overview

Encapsulate a single routing rule

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(route) ⇒ Route

Returns a new instance of Route.

Parameters:

  • route (ActionDispatch::Journey::Route)


16
17
18
19
20
# File 'lib/js_rails_routes/route.rb', line 16

def initialize(route)
  @route = route
  @name = route.name
  @path = route.path.spec.to_s.split('(').first
end

Instance Attribute Details

#nameString

Returns route name. It becomes JavaScript function name.

Returns:

  • (String)

    route name. It becomes JavaScript function name.



7
8
9
# File 'lib/js_rails_routes/route.rb', line 7

def name
  @name
end

#pathString (readonly)

Returns:

  • (String)


10
11
12
# File 'lib/js_rails_routes/route.rb', line 10

def path
  @path
end

#routeActionDispatch::Journey::Route (readonly)

Returns:

  • (ActionDispatch::Journey::Route)


13
14
15
# File 'lib/js_rails_routes/route.rb', line 13

def route
  @route
end

Instance Method Details

#match?Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
# File 'lib/js_rails_routes/route.rb', line 23

def match? # rubocop:disable Metrics/AbcSize
  return false if config.include_paths !~ path
  return false if config.exclude_paths =~ path
  return false if config.include_names !~ name
  return false if config.exclude_names =~ name

  config.route_filter.call(self)
end