Class: SelectRailsLog::Filter::TimeRangeFilter

Inherits:
BaseFilter show all
Includes:
RangePattern
Defined in:
lib/select_rails_log/filter/time_range_filter.rb

Constant Summary

Constants included from Constants

Constants::ACTION, Constants::CLIENT, Constants::COMPLETED, Constants::CONTROLLER, Constants::DEBUG, Constants::DEFAULT_OUTPUT, Constants::DURATION, Constants::HTTP_METHOD, Constants::HTTP_STATUS, Constants::ID, Constants::INTERVAL, Constants::LOGS, Constants::MESSAGE, Constants::PARAMETERS, Constants::PATH, Constants::PERFORMANCE, Constants::PERFORMANCE_ACTIVE_RECORD, Constants::PERFORMANCE_ALLOCATIONS, Constants::PERFORMANCE_VIEWS, Constants::PID, Constants::RAW_LOGS, Constants::REQUEST_ID, Constants::SEVERITY, Constants::STARTED, Constants::TIME

Instance Attribute Summary

Attributes inherited from Extension

#options

Instance Method Summary collapse

Methods inherited from BaseFilter

filter_type, #line_filter?, #request_filter?

Methods inherited from Extension

option_initializers

Constructor Details

#initializeTimeRangeFilter

Returns a new instance of TimeRangeFilter.



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/select_rails_log/filter/time_range_filter.rb', line 18

def initialize(...)
  super

  pattern = options[:pattern]
  return unless pattern

  begin
    @range = parse_range_pattern(pattern) { |time_str| Time.parse(time_str) }
  rescue ArgumentError
    raise CommandLineOptionError, "invalid time range pattern `#{pattern}`"
  end
end

Instance Method Details

#run(data) ⇒ Object



35
36
37
38
39
40
# File 'lib/select_rails_log/filter/time_range_filter.rb', line 35

def run(data)
  return true if @range.cover?(data[STARTED]) || @range.cover?(data[COMPLETED])

  range = data[STARTED]..data[COMPLETED]
  range.cover?(@range.begin) || range.cover?(@range.end)
end

#runnable?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/select_rails_log/filter/time_range_filter.rb', line 31

def runnable?
  !!@range
end