Sha256: cdcaec1570d3b462bfd3b13f6926d897f9af96b4f49ad69f212dcd06e467c829

Contents?: true

Size: 1008 Bytes

Versions: 1

Compression:

Stored size: 1008 Bytes

Contents

module Docushin
  class RouteSet
    attr_accessor :routes
    
    def initialize
      @routes = []
      Rails.application.routes.routes.each do |route|
        next if route.app.is_a?(ActionDispatch::Routing::Mapper::Constraints)
        next if route.app.is_a?(Sprockets::Environment)
        next if route.app == Docushin::Engine

        if (rack_app = discover_rack_app(route.app)) && rack_app.respond_to?(:routes)
          rack_app.routes.routes.each do |rack_route|
            @routes << Route.new(rack_route)
          end
        end
        @routes << Route.new(route)
      end
    end

    def discover_rack_app(app)
      class_name = app.class.name.to_s
      if class_name == "ActionDispatch::Routing::Mapper::Constraints"
        discover_rack_app(app.app)
      elsif class_name !~ /^ActionDispatch::Routing/
        app
      end
    end

    def find_by_filename_hash(hash)
      @routes.each do |route|
        return route if route.file_name == "#{hash}"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
docushin-0.0.1 lib/docushin/route_set.rb