Sha256: 79f54843063d5b09527b1741b390235b304abd41b33998a9a2cef99dd91338da

Contents?: true

Size: 809 Bytes

Versions: 2

Compression:

Stored size: 809 Bytes

Contents

module RateLimiter
  module Controller
    def self.included(base)
      base.before_filter :set_rate_limiter_source
      base.before_filter :set_rate_limiter_controller_info
      base.before_filter :set_rate_limiter_enabled_for_controller
    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
    end

    def set_rate_limiter_controller_info
      ::RateLimiter.controller_info = info_for_rate_limiter
    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.4 lib/rate_limiter/controller.rb
rate_limiter-0.0.3 lib/rate_limiter/controller.rb