Class: T1000::TransactionList

Inherits:
Array
  • Object
show all
Includes:
EnumerableObserver
Defined in:
lib/t-1000/transaction_list.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ip, timeout: 3600) ⇒ TransactionList

Returns a new instance of TransactionList.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/t-1000/transaction_list.rb', line 14

def initialize(ip, timeout: 3600)
  @timeout = timeout
  @key     = ActiveSupport::Cache.expand_cache_key [ip], :ip_request_tracker
  value    = T1000.cache.store.read(@key)
  replace Marshal.load value if value
  observe.added do
    T1000.cache.store.write @key, Marshal.dump(dup), expires_in: @timeout
  end
rescue Exception => e
  T1000.cache.store.delete @key
  raise e
end

Class Method Details

.for_ip(ip, timeout: 3600) ⇒ Object



10
11
12
# File 'lib/t-1000/transaction_list.rb', line 10

def self.for_ip(ip, timeout: 3600)
  new(ip, timeout: timeout)
end

Instance Method Details

#with_errorObject



31
32
33
# File 'lib/t-1000/transaction_list.rb', line 31

def with_error
  dup.replace select { |t| t.response.status >= 400 }
end

#within(time) ⇒ Object



27
28
29
# File 'lib/t-1000/transaction_list.rb', line 27

def within(time)
  dup.replace select { |t| t.time > time.ago }
end