Class: Gitlab::Sherlock::Collection
- Inherits:
-
Object
- Object
- Gitlab::Sherlock::Collection
- 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
- #add(transaction) ⇒ Object (also: #<<)
- #clear ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
- #find_transaction(id) ⇒ Object
-
#initialize ⇒ Collection
constructor
A new instance of Collection.
- #newest_first ⇒ Object
Constructor Details
#initialize ⇒ Collection
Returns a new instance of Collection.
13 14 15 16 |
# File 'lib/gitlab/sherlock/collection.rb', line 13 def initialize @transactions = [] @mutex = Mutex.new end |
Instance Method Details
#add(transaction) ⇒ Object Also known as: <<
18 19 20 |
# File 'lib/gitlab/sherlock/collection.rb', line 18 def add(transaction) synchronize { @transactions << transaction } end |
#clear ⇒ Object
28 29 30 |
# File 'lib/gitlab/sherlock/collection.rb', line 28 def clear synchronize { @transactions.clear } end |
#each(&block) ⇒ Object
24 25 26 |
# File 'lib/gitlab/sherlock/collection.rb', line 24 def each(&block) synchronize { @transactions.each(&block) } end |
#empty? ⇒ Boolean
32 33 34 |
# File 'lib/gitlab/sherlock/collection.rb', line 32 def empty? synchronize { @transactions.empty? } end |
#find_transaction(id) ⇒ Object
36 37 38 |
# File 'lib/gitlab/sherlock/collection.rb', line 36 def find_transaction(id) find { |trans| trans.id == id } end |
#newest_first ⇒ Object
40 41 42 |
# File 'lib/gitlab/sherlock/collection.rb', line 40 def newest_first sort { |a, b| b.finished_at <=> a.finished_at } end |