Class: OasRails::Extractors::RouteExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/oas_rails/extractors/route_extractor.rb

Constant Summary collapse

RAILS_DEFAULT_CONTROLLERS =
%w[
  rails
  action_mailbox
  action_cable
  active_storage
  turbo/native
].freeze

Class Method Summary collapse

Class Method Details

.clean_route(route) ⇒ Object



45
46
47
# File 'lib/oas_rails/extractors/route_extractor.rb', line 45

def clean_route(route)
  route.gsub('(.:format)', '').gsub(/:\w+/) { |match| "{#{match[1..]}}" }
end

.clear_cache(config: nil) ⇒ Object

Clear the cached routes.

When a config is given, only that config’s cache entry is cleared, forcing the next call to re-extract routes for that configuration. When called without arguments, the entire cache is cleared for all configurations.



30
31
32
33
34
35
36
37
38
# File 'lib/oas_rails/extractors/route_extractor.rb', line 30

def clear_cache(config: nil)
  if config
    @host_routes_cache&.delete(config.name)
    @host_paths_cache&.delete(config.name)
  else
    @host_routes_cache = nil
    @host_paths_cache = nil
  end
end

.host_paths(config:) ⇒ Object



40
41
42
43
# File 'lib/oas_rails/extractors/route_extractor.rb', line 40

def host_paths(config:)
  @host_paths_cache ||= {}
  @host_paths_cache[config.name] ||= host_routes(config:).map(&:path).uniq.sort
end

.host_routes(config:) ⇒ Object



19
20
21
22
# File 'lib/oas_rails/extractors/route_extractor.rb', line 19

def host_routes(config:)
  @host_routes_cache ||= {}
  @host_routes_cache[config.name] ||= extract_host_routes(config:)
end

.host_routes_by_path(path, config:) ⇒ Object



13
14
15
16
17
# File 'lib/oas_rails/extractors/route_extractor.rb', line 13

def host_routes_by_path(path, config:)
  @host_routes_cache ||= {}
  @host_routes_cache[config.name] ||= extract_host_routes(config:)
  @host_routes_cache[config.name].select { |r| r.path == path }
end