Class: LogBench::App::Sort
- Inherits:
-
Object
- Object
- LogBench::App::Sort
- Defined in:
- lib/log_bench/app/sort.rb
Constant Summary collapse
- MODES =
[:timestamp, :duration, :method, :status].freeze
Instance Method Summary collapse
- #cycle ⇒ Object
- #display_name ⇒ Object
- #duration? ⇒ Boolean
-
#initialize ⇒ Sort
constructor
A new instance of Sort.
- #method? ⇒ Boolean
- #sort_requests(requests) ⇒ Object
- #status? ⇒ Boolean
- #timestamp? ⇒ Boolean
Constructor Details
#initialize ⇒ Sort
Returns a new instance of Sort.
6 7 8 |
# File 'lib/log_bench/app/sort.rb', line 6 def initialize self.mode = :timestamp end |
Instance Method Details
#cycle ⇒ Object
10 11 12 13 14 |
# File 'lib/log_bench/app/sort.rb', line 10 def cycle current_index = MODES.index(mode) next_index = (current_index + 1) % MODES.length self.mode = MODES[next_index] end |
#display_name ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/log_bench/app/sort.rb', line 16 def display_name case mode when :timestamp then "TIMESTAMP" when :duration then "DURATION" when :method then "METHOD" when :status then "STATUS" end end |
#duration? ⇒ Boolean
44 45 46 |
# File 'lib/log_bench/app/sort.rb', line 44 def duration? mode == :duration end |
#method? ⇒ Boolean
48 49 50 |
# File 'lib/log_bench/app/sort.rb', line 48 def method? mode == :method end |
#sort_requests(requests) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/log_bench/app/sort.rb', line 25 def sort_requests(requests) case mode when :timestamp requests.sort_by { |req| req. || Time.at(0) } when :duration requests.sort_by { |req| -(req.duration || 0) } # Descending (slowest first) when :method requests.sort_by { |req| req.method || "" } when :status requests.sort_by { |req| -(req.status || 0) } # Descending (errors first) else requests end end |
#status? ⇒ Boolean
52 53 54 |
# File 'lib/log_bench/app/sort.rb', line 52 def status? mode == :status end |
#timestamp? ⇒ Boolean
40 41 42 |
# File 'lib/log_bench/app/sort.rb', line 40 def mode == :timestamp end |