Sha256: 8d650ce3536c8329db786d6b93d8549512904287e807f6709307ebb6e86b9a63

Contents?: true

Size: 1.25 KB

Versions: 18

Compression:

Stored size: 1.25 KB

Contents

module SoberSwag
  class Compiler
    ##
    # Compile multiple routes into a paths set.
    class Paths
      def initialize
        @routes = []
      end

      def add_route(route)
        @routes << route
      end

      def grouped_paths
        routes.group_by(&:path)
      end

      ##
      # Slightly weird method that gives you a compiled
      # paths list. Since this is only a compiler for paths,
      # it has *no idea* how to handle types. So, it takes a compiler
      # which it will use to do that for it.
      def paths_list(compiler)
        grouped_paths.transform_values do |values|
          values.map { |route|
            [route.method, compile_route(route, compiler)]
          }.to_h
        end
      end

      ##
      # Get a list of all types we discovered when compiling
      # the paths.
      def found_types
        return enum_for(:found_types) unless block_given?

        routes.each do |route|
          %i[body_class query_class path_params_class].each do |k|
            yield route.public_send(k) if route.public_send(k)
          end
        end
      end

      attr_reader :routes

      private

      def compile_route(route, compiler)
        SoberSwag::Compiler::Path.new(route, compiler).schema
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
sober_swag-0.19.0 lib/sober_swag/compiler/paths.rb
sober_swag-0.18.0 lib/sober_swag/compiler/paths.rb
sober_swag-0.17.0 lib/sober_swag/compiler/paths.rb
sober_swag-0.16.0 lib/sober_swag/compiler/paths.rb
sober_swag-0.15.0 lib/sober_swag/compiler/paths.rb
sober_swag-0.14.0 lib/sober_swag/compiler/paths.rb
sober_swag-0.13.0 lib/sober_swag/compiler/paths.rb
sober_swag-0.12.0 lib/sober_swag/compiler/paths.rb
sober_swag-0.11.0 lib/sober_swag/compiler/paths.rb
sober_swag-0.10.0 lib/sober_swag/compiler/paths.rb
sober_swag-0.9.0 lib/sober_swag/compiler/paths.rb
sober_swag-0.8.0 lib/sober_swag/compiler/paths.rb
sober_swag-0.7.0 lib/sober_swag/compiler/paths.rb
sober_swag-0.6.0 lib/sober_swag/compiler/paths.rb
sober_swag-0.5.0 lib/sober_swag/compiler/paths.rb
sober_swag-0.4.0 lib/sober_swag/compiler/paths.rb
sober_swag-0.3.0 lib/sober_swag/compiler/paths.rb
sober_swag-0.2.0 lib/sober_swag/compiler/paths.rb