Class: JSRailsRoutes::RouteSet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/js_rails_routes/route_set.rb

Overview

Encapsulate a set of routes

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, routes) ⇒ RouteSet

Returns a new instance of RouteSet.

Parameters:

  • name (String)

    engine name

  • routes (ActionDispatch::Routing::RouteSet)


36
37
38
39
40
41
42
43
# File 'lib/js_rails_routes/route_set.rb', line 36

def initialize(name, routes)
  @name = name
  @route_set = route_set
  @routes = routes.routes
                  .select(&:name)
                  .map { |route| Route.new(route) }
                  .select(&:match?)
end

Instance Attribute Details

#nameString (readonly)

Returns:

  • (String)


26
27
28
# File 'lib/js_rails_routes/route_set.rb', line 26

def name
  @name
end

#route_setActionDispatch::Routing::RouteSet (readonly)

Returns:

  • (ActionDispatch::Routing::RouteSet)


29
30
31
# File 'lib/js_rails_routes/route_set.rb', line 29

def route_set
  @route_set
end

#routesArray<JSRailsRoutes::Route> (readonly)

Returns:



32
33
34
# File 'lib/js_rails_routes/route_set.rb', line 32

def routes
  @routes
end

Class Method Details

.correct_matching_route_set_listArray<JSRailsRoutes::RouteSet>

Returns:



11
12
13
14
15
16
17
18
# File 'lib/js_rails_routes/route_set.rb', line 11

def self.correct_matching_route_set_list
  [
    RouteSet.new('Rails', ::Rails.application.routes),
    ::Rails::Engine.subclasses.map do |engine|
      RouteSet.new(engine.name, engine.routes)
    end
  ].flatten.select(&:match?)
end

Instance Method Details

#each {|JSRailsRoutes::Route| ... } ⇒ Object

Note:

Implementation for Enumerable

Yields:



23
# File 'lib/js_rails_routes/route_set.rb', line 23

delegate :each, to: :routes

#match?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/js_rails_routes/route_set.rb', line 46

def match?
  name !~ config.exclude_engines && routes.present? && config.route_set_filter.call(self)
end