Sha256: 2b181f72f672a4ac6581cd6c1bb6cfec5eae4217bc0db4ab68324cd0a881bbcd

Contents?: true

Size: 630 Bytes

Versions: 10

Compression:

Stored size: 630 Bytes

Contents

module GrapePathHelpers
  # methods to extend Grape::API's behavior so it can get a
  # list of routes from all APIs and decorate them with
  # the DecoratedRoute class
  module AllRoutes
    def decorated_routes
      # memoize so that construction of decorated routes happens once
      @decorated_routes ||= all_routes
                            .map { |r| DecoratedRoute.new(r) }
                            .sort_by { |r| -r.dynamic_path_segments.count }
    end

    def all_routes
      routes = subclasses.flat_map { |s| s.send(:prepare_routes) }
      routes.uniq { |r| r.options.merge(path: r.path) }
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
grape-path-helpers-1.3.0 lib/grape-path-helpers/all_routes.rb
grape-path-helpers-1.2.0 lib/grape-path-helpers/all_routes.rb
grape-path-helpers-1.1.0 lib/grape-path-helpers/all_routes.rb
grape-path-helpers-1.0.6 lib/grape-path-helpers/all_routes.rb
grape-path-helpers-1.0.5 lib/grape-path-helpers/all_routes.rb
grape-path-helpers-1.0.4 lib/grape-path-helpers/all_routes.rb
grape-path-helpers-1.0.3 lib/grape-path-helpers/all_routes.rb
grape-path-helpers-1.0.2 lib/grape-path-helpers/all_routes.rb
grape-path-helpers-1.0.1 lib/grape-path-helpers/all_routes.rb
grape-path-helpers-1.0.0 lib/grape-path-helpers/all_routes.rb