Class: GlobalErrorHandler::AppException
- Inherits:
-
Object
- Object
- GlobalErrorHandler::AppException
- Defined in:
- lib/global_error_handler/app_exception.rb
Overview
:nodoc:
Class Method Summary collapse
- .all(start, field = nil, filter = nil) ⇒ Object
- .count(field = nil, filter = nil) ⇒ Object
- .delete(id) ⇒ Object
- .delete_all(ids) ⇒ Object
- .filtered_ids_by(field, str, len = 1000, start = 0) ⇒ Object
- .filters_for(field) ⇒ Object
- .find(id) ⇒ Object
- .truncate(filter = nil, opts = {}) ⇒ Object
Class Method Details
.all(start, field = nil, filter = nil) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/global_error_handler/app_exception.rb', line 4 def all(start, field = nil, filter = nil) start ||= 0 if field && filter keys = Redis.filter_exception_keys start, "error_#{field}", filter else keys = Redis.exception_keys start end Redis.find_all keys end |
.count(field = nil, filter = nil) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/global_error_handler/app_exception.rb', line 14 def count(field = nil, filter = nil) if field && filter Redis.filtered_exceptions_count("error_#{field}", filter) else Redis.exceptions_count end end |
.delete(id) ⇒ Object
27 28 29 30 |
# File 'lib/global_error_handler/app_exception.rb', line 27 def delete(id) return if id.blank? Redis.delete exception_key(id) end |
.delete_all(ids) ⇒ Object
32 33 34 35 36 |
# File 'lib/global_error_handler/app_exception.rb', line 32 def delete_all(ids) return if ids.blank? keys = ids.map { |id| exception_key id } Redis.delete_all keys end |
.filtered_ids_by(field, str, len = 1000, start = 0) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/global_error_handler/app_exception.rb', line 61 def filtered_ids_by(field, str, len = 1000, start = 0) keys = Redis.filter_exception_keys start, "error_#{field}", str, len return [] if keys.blank? keys.map do |key| begin key.split(':').last rescue nil end end.compact end |
.filters_for(field) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/global_error_handler/app_exception.rb', line 52 def filters_for(field) keys = Redis.filter_keys_for "error_#{field}" return [] if keys.blank? keys.map do |key| key =~ /^#{Redis::FILTER_KEY_PREFIX}:error_#{field}:(.*)/ Regexp.last_match(1) end end |
.find(id) ⇒ Object
22 23 24 25 |
# File 'lib/global_error_handler/app_exception.rb', line 22 def find(id) return if id.blank? Redis.find exception_key(id) end |
.truncate(filter = nil, opts = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/global_error_handler/app_exception.rb', line 38 def truncate(filter = nil, opts = {}) if filter field = opts.delete(:field) total = opts.delete(:total) || 1000 size = 1000 (total / size.to_f).ceil.times do |iteration| ids = filtered_ids_by field, filter, size, iteration delete_all ids unless ids.blank? end else Redis.truncate! end end |