Sha256: f66bd866b593767782ef29b3a786c1b96c6c84a45ebdaf28b2e92530ff4daf6c

Contents?: true

Size: 590 Bytes

Versions: 1

Compression:

Stored size: 590 Bytes

Contents

module GrapeRouteHelpers
  # 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) }
    end

    def all_routes
      routes = subclasses.flat_map { |s| s.send(:prepare_routes) }
      # delete duplicate routes
      routes.uniq do |route|
        route.instance_variable_get( :@options )
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
grape-route-helpers-1.2.2 lib/grape-route-helpers/all_routes.rb