Class: SelectRailsLog::Filter::HttpStatusFilter
- Inherits:
-
BaseFilter
- Object
- Extension
- BaseFilter
- SelectRailsLog::Filter::HttpStatusFilter
- Defined in:
- lib/select_rails_log/filter/http_status_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
Instance Method Summary collapse
-
#initialize ⇒ HttpStatusFilter
constructor
A new instance of HttpStatusFilter.
- #run(data) ⇒ Object
- #runnable? ⇒ Boolean
Methods inherited from BaseFilter
filter_type, #line_filter?, #request_filter?
Methods inherited from Extension
Constructor Details
#initialize ⇒ HttpStatusFilter
Returns a new instance of HttpStatusFilter.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/select_rails_log/filter/http_status_filter.rb', line 14 def initialize(...) super @includes = @excludes = [] pattern = [:pattern] return unless pattern m = /\A([,\d]+)?(?:!([,\d]+))?\z/.match(pattern) raise CommandLineOptionError, "invalid HTTP statuses pattern `#{pattern}`" unless m @includes = m[1] ? m[1].split(",") : [] @excludes = m[2] ? m[2].split(",") : [] end |
Instance Method Details
#run(data) ⇒ Object
32 33 34 35 36 |
# File 'lib/select_rails_log/filter/http_status_filter.rb', line 32 def run(data) http_status = data[HTTP_STATUS] @excludes.none? { |exc| http_status.index(exc)&.zero? } && (@includes.empty? || @includes.any? { |inc| http_status.index(inc)&.zero? }) end |
#runnable? ⇒ Boolean
28 29 30 |
# File 'lib/select_rails_log/filter/http_status_filter.rb', line 28 def runnable? @includes.any? || @excludes.any? end |