Class: Gitlab::Sherlock::Collection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/gitlab/sherlock/collection.rb

Overview

A collection of transactions recorded by Sherlock.

Method calls for this class are synchronized using a mutex to allow sharing of a single Collection instance between threads (e.g. when using Puma as a webserver).

Instance Method Summary collapse

Constructor Details

#initializeCollection


11
12
13
14
# File 'lib/gitlab/sherlock/collection.rb', line 11

def initialize
  @transactions = []
  @mutex = Mutex.new
end

Instance Method Details

#add(transaction) ⇒ Object Also known as: <<


16
17
18
# File 'lib/gitlab/sherlock/collection.rb', line 16

def add(transaction)
  synchronize { @transactions << transaction }
end

#clearObject


26
27
28
# File 'lib/gitlab/sherlock/collection.rb', line 26

def clear
  synchronize { @transactions.clear }
end

#each(&block) ⇒ Object


22
23
24
# File 'lib/gitlab/sherlock/collection.rb', line 22

def each(&block)
  synchronize { @transactions.each(&block) }
end

#empty?Boolean


30
31
32
# File 'lib/gitlab/sherlock/collection.rb', line 30

def empty?
  synchronize { @transactions.empty? }
end

#find_transaction(id) ⇒ Object


34
35
36
# File 'lib/gitlab/sherlock/collection.rb', line 34

def find_transaction(id)
  find { |trans| trans.id == id }
end

#newest_firstObject


38
39
40
# File 'lib/gitlab/sherlock/collection.rb', line 38

def newest_first
  sort { |a, b| b.finished_at <=> a.finished_at }
end