Class: Sherlog::Filter
- Inherits:
-
Object
- Object
- Sherlog::Filter
- Defined in:
- lib/sherlog_holmes/filter.rb
Class Method Summary collapse
- .category(expression) ⇒ Object
- .custom_attribute(attribute_name, expression) ⇒ Object
- .exception(expression) ⇒ Object
- .exceptions ⇒ Object
- .expression(expression) ⇒ Object
- .level(expression) ⇒ Object
- .message(expression) ⇒ Object
- .origin(expression) ⇒ Object
Instance Method Summary collapse
- #accept?(object) ⇒ Boolean
- #and(other_filter = nil, &other_block) ⇒ Object
- #call(object) ⇒ Object
-
#initialize(&block) ⇒ Filter
constructor
A new instance of Filter.
- #negate ⇒ Object
- #or(other_filter = nil, &other_block) ⇒ Object
Constructor Details
#initialize(&block) ⇒ Filter
Returns a new instance of Filter.
27 28 29 |
# File 'lib/sherlog_holmes/filter.rb', line 27 def initialize(&block) @block = block end |
Class Method Details
.category(expression) ⇒ Object
82 83 84 85 86 |
# File 'lib/sherlog_holmes/filter.rb', line 82 def self.category(expression) Filter::new do |entry| expression(expression).accept? entry.category end end |
.custom_attribute(attribute_name, expression) ⇒ Object
114 115 116 117 118 |
# File 'lib/sherlog_holmes/filter.rb', line 114 def self.custom_attribute(attribute_name, expression) Filter::new do |entry| expression(expression).accept? entry[attribute_name] end end |
.exception(expression) ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/sherlog_holmes/filter.rb', line 100 def self.exception(expression) Filter::new do |entry| entry.exceptions.find do |exception| expression(expression).accept? exception end end end |
.exceptions ⇒ Object
108 109 110 111 112 |
# File 'lib/sherlog_holmes/filter.rb', line 108 def self.exceptions Filter::new do |entry| entry.exception? end end |
.expression(expression) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/sherlog_holmes/filter.rb', line 59 def self.expression(expression) expression = expression.to_s Filter::new do |object| wildcard_at_start = expression.start_with? '*' wildcard_at_end = expression.end_with? '*' if wildcard_at_start and wildcard_at_end object.to_s.index expression[1...-1] elsif wildcard_at_start object.to_s.end_with? expression[1..-1] elsif wildcard_at_end object.to_s.start_with? expression[0...-1] else object.to_s == expression.to_s end end end |
.level(expression) ⇒ Object
76 77 78 79 80 |
# File 'lib/sherlog_holmes/filter.rb', line 76 def self.level(expression) Filter::new do |entry| entry.level.to_s == expression.to_s end end |
.message(expression) ⇒ Object
94 95 96 97 98 |
# File 'lib/sherlog_holmes/filter.rb', line 94 def self.(expression) Filter::new do |entry| expression(expression).accept? entry. end end |
.origin(expression) ⇒ Object
88 89 90 91 92 |
# File 'lib/sherlog_holmes/filter.rb', line 88 def self.origin(expression) Filter::new do |entry| expression(expression).accept? entry.origin end end |
Instance Method Details
#accept?(object) ⇒ Boolean
35 36 37 |
# File 'lib/sherlog_holmes/filter.rb', line 35 def accept?(object) @block.call object end |
#and(other_filter = nil, &other_block) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/sherlog_holmes/filter.rb', line 39 def and(other_filter = nil, &other_block) other_filter ||= Filter::new &other_block Filter::new do |entry| self.accept?(entry) && other_filter.accept?(entry) end end |
#call(object) ⇒ Object
31 32 33 |
# File 'lib/sherlog_holmes/filter.rb', line 31 def call(object) accept? object end |
#negate ⇒ Object
53 54 55 56 57 |
# File 'lib/sherlog_holmes/filter.rb', line 53 def negate Filter::new do |entry| !self.accept?(entry) end end |
#or(other_filter = nil, &other_block) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/sherlog_holmes/filter.rb', line 46 def or(other_filter = nil, &other_block) other_filter ||= Filter::new &other_block Filter::new do |entry| self.accept?(entry) || other_filter.accept?(entry) end end |