Sha256: 485663f33246b09e757c6ef5aa4db79b02c0b215d509b3ca4778372fa4f7e82f

Contents?: true

Size: 801 Bytes

Versions: 1

Compression:

Stored size: 801 Bytes

Contents

module RouteDog
  module Middleware
    class Watcher < RouteDog
      def initialize(app)
        @app = app
        super
      end

      def call(env)
        @env = env

        status, headers, response = @app.call(env)

        store_route if status.to_i < 400

        [status, headers, response]
      end

    private

      def store_route
        @watched_routes[identify_controller] ||= {}
        @watched_routes[identify_controller][identify_action] ||= []
        @watched_routes[identify_controller][identify_action] << request_method.to_s
        @watched_routes[identify_controller][identify_action].uniq!
        File.open(Watcher.config_file, "w+") {|file| file.puts(@watched_routes.to_yaml) }
      rescue ActionController::RoutingError
        false
      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/watcher.rb