Sha256: c8b14e892db8cfe7c223ff4dbde95f88ead7d247b6bf97bca48f801cfddc48b6

Contents?: true

Size: 1.26 KB

Versions: 2

Compression:

Stored size: 1.26 KB

Contents

require 'singleton'

require 'rate_limiter/config'
require 'rate_limiter/controller'
require 'rate_limiter/model'

module RateLimiter
  def self.enabled=(value)
    RateLimiter.config.enabled = value
  end

  def self.enabled?
    !!RateLimiter.config.enabled
  end

  def self.enabled_for_controller=(value)
    RateLimiter.store[:request_enabled_for_controller] = value
  end

  def self.enabled_for_controller?
    !!RateLimiter.store[:request_enabled_for_controller]
  end

  def self.timestamp_field=(field_name)
    RateLimiter.config.timestamp_field = field_name
  end

  def self.timestamp_field
    RateLimiter.config.timestamp_field
  end

  def self.source=(value)
    RateLimiter.store[:source] = value
  end

  def self.source
    RateLimiter.store[:source]
  end

  def self.controller_info=(value)
    RateLimiter.store[:controller_info] = value
  end

  def self.controller_info
    RateLimiter.store[:controller_info]
  end

  private

  def self.store
    Thread.current[:rate_limiter] || { :request_enabled_for_controller => true }
  end

  def self.config
    @@config ||= RateLimiter::Config.instance
  end
end

ActiveSupport.on_load(:active_record) do
  include RateLimiter::Model
end

ActiveSupport.on_load(:action_controller) do
  include RateLimiter::Controller
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rate_limiter-0.0.4 lib/rate_limiter.rb
rate_limiter-0.0.3 lib/rate_limiter.rb