Sha256: 7712b00c7ed872a7ff55d90bef3c5f1988db3ae884fe4d04eaea33c901692955

Contents?: true

Size: 863 Bytes

Versions: 2

Compression:

Stored size: 863 Bytes

Contents

module RateLimiter
  module Controller
    def self.included(base)
      base.before_filter :set_rate_limiter_enabled_for_controller
      base.before_filter :set_rate_limiter_source, :set_rate_limiter_controller_info
    end

    protected

    def user_for_rate_limiter
      current_user rescue nil
    end

    def info_for_rate_limiter
      {}
    end

    def rate_limiter_enabled_for_controller
      true
    end

    private

    def set_rate_limiter_source
      ::RateLimiter.source = user_for_rate_limiter if rate_limiter_enabled_for_controller
    end

    def set_rate_limiter_controller_info
      ::RateLimiter.controller_info = info_for_rate_limiter if rate_limiter_enabled_for_controller
    end

    def set_rate_limiter_enabled_for_controller
      ::RateLimiter.enabled_for_controller = rate_limiter_enabled_for_controller
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rate_limiter-0.0.6 lib/rate_limiter/controller.rb
rate_limiter-0.0.5 lib/rate_limiter/controller.rb