Class: Whoops::Filter

Inherits:
Object
  • Object
show all
Includes:
FieldNames, Mongoid::Document
Defined in:
app/models/whoops/filter.rb

Constant Summary collapse

FILTERED_FIELDS =
[:service, :environment, :event_type, :message, :details]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#authorized_service_lookupObject

Returns the value of attribute authorized_service_lookup.



2
3
4
# File 'app/models/whoops/filter.rb', line 2

def authorized_service_lookup
  @authorized_service_lookup
end

Class Method Details

.clean_params(params) ⇒ Object



66
67
68
69
70
71
72
# File 'app/models/whoops/filter.rb', line 66

def clean_params(params)
  params.inject({}){ |hash, current|
    allowed_values = current.last.keys
    hash[current.first] = allowed_values.include?("all") ? [] : allowed_values
    hash
  }
end

.new_from_params(params) ⇒ Object



58
59
60
61
62
63
64
# File 'app/models/whoops/filter.rb', line 58

def new_from_params(params)
  if params
    f = new(clean_params(params))
  else
    new
  end
end

Instance Method Details

#matches_event_group?(event_group) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
# File 'app/models/whoops/filter.rb', line 25

def matches_event_group?(event_group)
  FILTERED_FIELDS.all? do |field|
    if self.send(field).blank?
      true
    else
      /^(#{self.send(field).join("|")})$/ =~ event_group.send(field)
    end
  end
end

#serviceObject



39
40
41
42
43
44
45
# File 'app/models/whoops/filter.rb', line 39

def service
  if authorized_services_provided?
    authorized_services
  else
    attributes["service"]
  end
end

#to_query_documentObject



15
16
17
18
19
20
21
22
23
# File 'app/models/whoops/filter.rb', line 15

def to_query_document
  doc = attributes.except(:_id, "_id", :_type, "_type").delete_if{|k, v| v.blank?}
  # match all services under namespace. ie, if "app" given, match "app.web", "app.backend" etc
  doc["service"] = service.collect{ |d| /^#{d}/ } unless service.blank?
  doc.inject({}) do |hash, current|
    hash[current.first.to_sym.in] = current.last unless current.last.empty?
    hash
  end
end

#update_from_params(params) ⇒ Object



35
36
37
# File 'app/models/whoops/filter.rb', line 35

def update_from_params(params)
  update_attributes(self.class.clean_params(params))
end