Class: Notice

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
app/models/notice.rb

Instance Method Summary collapse

Instance Method Details

#actionObject


60
61
62
# File 'app/models/notice.rb', line 60

def action
  request['action']
end

#app_versionObject


137
138
139
140
141
# File 'app/models/notice.rb', line 137

def app_version
  if server_environment
    server_environment['app-version'] || ''
  end
end

#componentObject


56
57
58
# File 'app/models/notice.rb', line 56

def component
  request['component']
end

#emailable?Boolean

Returns:

  • (Boolean)

116
117
118
# File 'app/models/notice.rb', line 116

def emailable?
  app.email_at_notices.include?(similar_count)
end

#env_varsObject


96
97
98
# File 'app/models/notice.rb', line 96

def env_vars
  request['cgi-data'] || {}
end

#environment_nameObject


52
53
54
# File 'app/models/notice.rb', line 52

def environment_name
  server_environment['server-environment'] || server_environment['environment-name']
end

#hostObject


78
79
80
81
82
83
# File 'app/models/notice.rb', line 78

def host
  uri = url && URI.parse(url)
  uri.blank? ? "N/A" : uri.host
rescue URI::InvalidURIError
  "N/A"
end

#in_app_backtrace_linesObject


108
109
110
# File 'app/models/notice.rb', line 108

def in_app_backtrace_lines
  backtrace_lines.in_app
end

#paramsObject


100
101
102
# File 'app/models/notice.rb', line 100

def params
  request['params'] || {}
end

#project_rootObject

TODO: Move on decorator maybe


131
132
133
134
135
# File 'app/models/notice.rb', line 131

def project_root
  if server_environment
    server_environment['project-root'] || ''
  end
end

#requestObject


70
71
72
# File 'app/models/notice.rb', line 70

def request
  super || {}
end

#sessionObject


104
105
106
# File 'app/models/notice.rb', line 104

def session
  request['session'] || {}
end

#should_email?Boolean

Returns:

  • (Boolean)

120
121
122
# File 'app/models/notice.rb', line 120

def should_email?
  app.emailable? && emailable?
end

#should_notify?Boolean

Returns:

  • (Boolean)

124
125
126
# File 'app/models/notice.rb', line 124

def should_notify?
  app.notification_service.notify_at_notices.include?(0) || app.notification_service.notify_at_notices.include?(similar_count)
end

#similar_countObject


112
113
114
# File 'app/models/notice.rb', line 112

def similar_count
  problem.notices_count
end

#to_curlObject


85
86
87
88
89
90
91
92
93
94
# File 'app/models/notice.rb', line 85

def to_curl
  return "N/A" if url.blank?
  headers = %w(Accept Accept-Encoding Accept-Language Cookie Referer User-Agent).each_with_object([]) do |name, h|
    if value = env_vars["HTTP_#{name.underscore.upcase}"]
      h << "-H '#{name}: #{value}'"
    end
  end

  "curl -X #{env_vars['REQUEST_METHOD'] || 'GET'} #{headers.join(' ')} #{url}"
end

#urlObject


74
75
76
# File 'app/models/notice.rb', line 74

def url
  request['url']
end

#user_agentObject


39
40
41
42
# File 'app/models/notice.rb', line 39

def user_agent
  agent_string = env_vars['HTTP_USER_AGENT']
  agent_string.blank? ? nil : UserAgent.parse(agent_string)
end

#user_agent_stringObject


44
45
46
47
48
49
50
# File 'app/models/notice.rb', line 44

def user_agent_string
  if user_agent.nil? || user_agent.none?
    "N/A"
  else
    "#{user_agent.browser} #{user_agent.version} (#{user_agent.os})"
  end
end

#whereObject


64
65
66
67
68
# File 'app/models/notice.rb', line 64

def where
  where = component.to_s.dup
  where << "##{action}" if action.present?
  where
end