Module: ActiveResourceThrottle

Defined in:
lib/active_resource_throttle.rb

Defined Under Namespace

Modules: ClassInheritableAttributes, ClassMethods

Constant Summary collapse

VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.included(klass) ⇒ Object

Callback invoked when ActiveResourceThrottle is included in a class. Note that the class must implement a connection class method for this to work (e.g, is an instance of ActiveResource::Base).



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/active_resource_throttle.rb', line 123

def self.included(klass)
  if klass.respond_to?(:connection)
    klass.instance_eval do      
      extend ClassMethods
      cattr_inheritable :sleep_interval, 
                        :throttle_interval, 
                        :throttle_request_limit,
                        :request_history
      class << klass
        alias_method :connection_without_throttle, :connection
        alias_method :connection, :connection_with_throttle  
      end
    end
  else
    raise StandardError, "Cannot include throttle if class doesn't include a #connection class method."
  end 
end