Sha256: 5c0af1e02b79b05cf9f7c38badd636b5d431e88cd944b514b54b5716d8cfdf8c

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

require 'rack'

module RouteDog
  module Middleware
    class RouteDog
      def initialize(app)
        require File.join(Rails.root, 'config/routes.rb')
        initialize_yaml_file
      end

      def self.config_file
        File.join(Rails.root, 'config', 'route_dog_routes.yml')
      end

      def initialize_yaml_file
        @watched_routes = YAML.load_file(Watcher.config_file)
      rescue Errno::ENOENT
        @watched_routes = {}
      end

      def request_path
        @env['PATH_INFO']
      end

      def request_method
        @env['REQUEST_METHOD'].downcase.to_sym
      end

      def identify_controller
        identify_path[:controller]
      end

      def identify_action
        identify_path[:action]
      end

      def route_tested?
        initialize_yaml_file
        begin
          @watched_routes[identify_controller.to_s][identify_action.to_s].include?(request_method.to_s)
        rescue
          false
        end
      end

      def identify_path
        Rails.application.routes.recognize_path(request_path, :method => request_method)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
route_dog-2.0.1 lib/route_dog/middleware/route_dog.rb