Sha256: e43220c53215f29bf81445b2b528deef0166680e9bdf827ed158586d1f4e98eb

Contents?: true

Size: 1.26 KB

Versions: 2

Compression:

Stored size: 1.26 KB

Contents

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)
    rate_limiter_store[:request_enabled_for_controller] = value
  end

  def self.enabled_for_controller?
    !!rate_limiter_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)
    rate_limiter_store[:source] = value
  end

  def self.source
    rate_limiter_store[:source]
  end

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

  def self.controller_info
    rate_limiter_store[:controller_info]
  end

  private

  def self.rate_limiter_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.6 lib/rate_limiter.rb
rate_limiter-0.0.5 lib/rate_limiter.rb