Class: Js::Routes::Rails::RouteFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/js-routes/rails/route_finder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(application_routes = nil) ⇒ RouteFinder

Returns a new instance of RouteFinder.



7
8
9
10
11
# File 'lib/js-routes/rails/route_finder.rb', line 7

def initialize(application_routes = nil)
  @routes = {}
  @application_routes = application_routes
  find_routes
end

Instance Attribute Details

#routesObject (readonly)

Returns the value of attribute routes.



5
6
7
# File 'lib/js-routes/rails/route_finder.rb', line 5

def routes
  @routes
end

Instance Method Details

#find_routesObject



13
14
15
16
17
18
19
# File 'lib/js-routes/rails/route_finder.rb', line 13

def find_routes
  @application_routes.to_a.each do |route|
    if route.defaults.key?(:export) && route.name.present?
      @routes[path_helper(route)] = path(route)
    end
  end
end

#path(route) ⇒ Object



25
26
27
# File 'lib/js-routes/rails/route_finder.rb', line 25

def path(route)
  route.path.spec.to_s.chomp("(.:format)")
end

#path_helper(route) ⇒ Object



21
22
23
# File 'lib/js-routes/rails/route_finder.rb', line 21

def path_helper(route)
  "#{route.name}_path"
end