Class: LogBench::Log::Collection
- Inherits:
-
Object
- Object
- LogBench::Log::Collection
- Includes:
- Enumerable
- Defined in:
- lib/log_bench/log/collection.rb
Instance Attribute Summary collapse
-
#entries ⇒ Object
Returns the value of attribute entries.
Instance Method Summary collapse
- #cache_operations ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
- #filter_by_method(method) ⇒ Object
- #filter_by_path(path_pattern) ⇒ Object
- #filter_by_status(status_range) ⇒ Object
-
#initialize(input) ⇒ Collection
constructor
A new instance of Collection.
- #queries ⇒ Object
- #requests ⇒ Object
- #size ⇒ Object
- #slow_requests(threshold_ms = 1000) ⇒ Object
- #sort_by_duration ⇒ Object
- #sort_by_timestamp ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(input) ⇒ Collection
Returns a new instance of Collection.
10 11 12 |
# File 'lib/log_bench/log/collection.rb', line 10 def initialize(input) self.entries = parse_input(input) end |
Instance Attribute Details
#entries ⇒ Object
Returns the value of attribute entries.
8 9 10 |
# File 'lib/log_bench/log/collection.rb', line 8 def entries @entries end |
Instance Method Details
#cache_operations ⇒ Object
34 35 36 |
# File 'lib/log_bench/log/collection.rb', line 34 def cache_operations entries.flat_map(&:cache_operations) end |
#each(&block) ⇒ Object
14 15 16 |
# File 'lib/log_bench/log/collection.rb', line 14 def each(&block) entries.each(&block) end |
#empty? ⇒ Boolean
22 23 24 |
# File 'lib/log_bench/log/collection.rb', line 22 def empty? entries.empty? end |
#filter_by_method(method) ⇒ Object
38 39 40 41 |
# File 'lib/log_bench/log/collection.rb', line 38 def filter_by_method(method) filtered_requests = requests.select { |req| req.method == method.upcase } create_collection_from_requests(filtered_requests) end |
#filter_by_path(path_pattern) ⇒ Object
43 44 45 46 |
# File 'lib/log_bench/log/collection.rb', line 43 def filter_by_path(path_pattern) filtered_requests = requests.select { |req| req.path.include?(path_pattern) } create_collection_from_requests(filtered_requests) end |
#filter_by_status(status_range) ⇒ Object
48 49 50 51 |
# File 'lib/log_bench/log/collection.rb', line 48 def filter_by_status(status_range) filtered_requests = requests.select { |req| status_range.include?(req.status) } create_collection_from_requests(filtered_requests) end |
#queries ⇒ Object
30 31 32 |
# File 'lib/log_bench/log/collection.rb', line 30 def queries entries.flat_map(&:queries) end |
#requests ⇒ Object
26 27 28 |
# File 'lib/log_bench/log/collection.rb', line 26 def requests entries.select { |entry| entry.is_a?(Request) } end |
#size ⇒ Object
18 19 20 |
# File 'lib/log_bench/log/collection.rb', line 18 def size entries.size end |
#slow_requests(threshold_ms = 1000) ⇒ Object
53 54 55 56 |
# File 'lib/log_bench/log/collection.rb', line 53 def slow_requests(threshold_ms = 1000) filtered_requests = requests.select { |req| req.duration && req.duration > threshold_ms } create_collection_from_requests(filtered_requests) end |
#sort_by_duration ⇒ Object
58 59 60 61 |
# File 'lib/log_bench/log/collection.rb', line 58 def sort_by_duration sorted_requests = requests.sort_by { |req| -(req.duration || 0) } create_collection_from_requests(sorted_requests) end |
#sort_by_timestamp ⇒ Object
63 64 65 66 |
# File 'lib/log_bench/log/collection.rb', line 63 def sorted_requests = requests.sort_by(&:timestamp) create_collection_from_requests(sorted_requests) end |
#to_a ⇒ Object
68 69 70 |
# File 'lib/log_bench/log/collection.rb', line 68 def to_a entries end |