raygun4ruby 3.1.1 → 3.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +18 -18
  3. data/.rspec +1 -1
  4. data/.travis.yml +20 -12
  5. data/CHANGELOG.md +127 -109
  6. data/Gemfile +4 -4
  7. data/LICENSE.txt +22 -22
  8. data/README.md +420 -420
  9. data/Rakefile +27 -27
  10. data/examples/sinatras_raygun.rb +17 -17
  11. data/lib/generators/raygun/install_generator.rb +26 -26
  12. data/lib/raygun.rb +179 -182
  13. data/lib/raygun/affected_user.rb +59 -59
  14. data/lib/raygun/breadcrumbs.rb +34 -34
  15. data/lib/raygun/breadcrumbs/breadcrumb.rb +34 -30
  16. data/lib/raygun/breadcrumbs/store.rb +86 -76
  17. data/lib/raygun/client.rb +305 -302
  18. data/lib/raygun/configuration.rb +194 -194
  19. data/lib/raygun/error.rb +10 -10
  20. data/lib/raygun/javascript_tracker.rb +42 -42
  21. data/lib/raygun/middleware/breadcrumbs_store_initializer.rb +19 -19
  22. data/lib/raygun/middleware/javascript_exception_tracking.rb +32 -32
  23. data/lib/raygun/middleware/rack_exception_interceptor.rb +18 -18
  24. data/lib/raygun/middleware/rails_insert_affected_user.rb +26 -26
  25. data/lib/raygun/railtie.rb +39 -39
  26. data/lib/raygun/services/apply_whitelist_filter_to_payload.rb +27 -27
  27. data/lib/raygun/sidekiq.rb +71 -67
  28. data/lib/raygun/testable.rb +22 -22
  29. data/lib/raygun/version.rb +3 -3
  30. data/lib/raygun4ruby.rb +1 -1
  31. data/lib/resque/failure/raygun.rb +25 -25
  32. data/lib/tasks/raygun.tasks +7 -7
  33. data/raygun4ruby.gemspec +45 -45
  34. data/spec/dummy/.gitignore +17 -0
  35. data/spec/dummy/Gemfile +47 -0
  36. data/spec/dummy/README.rdoc +28 -0
  37. data/spec/dummy/Rakefile +6 -6
  38. data/spec/dummy/app/assets/config/manifest.js +3 -3
  39. data/spec/dummy/app/assets/images/.keep +0 -0
  40. data/spec/dummy/app/assets/javascripts/application.js +13 -15
  41. data/spec/dummy/app/assets/stylesheets/application.css +15 -15
  42. data/spec/dummy/app/controllers/application_controller.rb +5 -2
  43. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  44. data/spec/dummy/app/controllers/home_controller.rb +4 -4
  45. data/spec/dummy/app/helpers/application_helper.rb +2 -2
  46. data/spec/dummy/app/{assets/javascripts/channels → mailers}/.keep +0 -0
  47. data/spec/dummy/{storage → app/models}/.keep +0 -0
  48. data/spec/dummy/app/models/concerns/.keep +0 -0
  49. data/spec/dummy/app/views/home/index.html.erb +3 -3
  50. data/spec/dummy/app/views/home/index.json.erb +1 -1
  51. data/spec/dummy/app/views/layouts/application.html.erb +14 -15
  52. data/spec/dummy/bin/bundle +3 -3
  53. data/spec/dummy/bin/rails +9 -4
  54. data/spec/dummy/bin/rake +9 -4
  55. data/spec/dummy/bin/setup +29 -36
  56. data/spec/dummy/bin/spring +17 -0
  57. data/spec/dummy/config.ru +4 -5
  58. data/spec/dummy/config/application.rb +26 -18
  59. data/spec/dummy/config/boot.rb +3 -5
  60. data/spec/dummy/config/database.yml +25 -25
  61. data/spec/dummy/config/environment.rb +5 -5
  62. data/spec/dummy/config/environments/development.rb +41 -61
  63. data/spec/dummy/config/environments/production.rb +79 -94
  64. data/spec/dummy/config/environments/test.rb +42 -46
  65. data/spec/dummy/config/initializers/assets.rb +11 -14
  66. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -7
  67. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -5
  68. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -4
  69. data/spec/dummy/config/initializers/inflections.rb +16 -16
  70. data/spec/dummy/config/initializers/mime_types.rb +4 -4
  71. data/spec/dummy/config/initializers/session_store.rb +3 -0
  72. data/spec/dummy/config/initializers/to_time_preserves_timezone.rb +10 -0
  73. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -14
  74. data/spec/dummy/config/locales/en.yml +23 -33
  75. data/spec/dummy/config/routes.rb +58 -3
  76. data/spec/dummy/config/secrets.yml +22 -0
  77. data/spec/dummy/db/seeds.rb +7 -0
  78. data/spec/dummy/db/test.sqlite3 +0 -0
  79. data/spec/dummy/lib/assets/.keep +0 -0
  80. data/spec/dummy/{public/apple-touch-icon-precomposed.png → lib/tasks/.keep} +0 -0
  81. data/spec/dummy/public/404.html +67 -67
  82. data/spec/dummy/public/422.html +67 -67
  83. data/spec/dummy/public/500.html +66 -66
  84. data/spec/dummy/public/favicon.ico +0 -0
  85. data/spec/dummy/public/robots.txt +5 -0
  86. data/spec/dummy/{public/apple-touch-icon.png → test/controllers/.keep} +0 -0
  87. data/spec/dummy/test/fixtures/.keep +0 -0
  88. data/spec/dummy/test/helpers/.keep +0 -0
  89. data/spec/dummy/test/integration/.keep +0 -0
  90. data/spec/dummy/test/mailers/.keep +0 -0
  91. data/spec/dummy/test/models/.keep +0 -0
  92. data/spec/dummy/test/test_helper.rb +10 -0
  93. data/spec/dummy/vendor/assets/javascripts/.keep +0 -0
  94. data/spec/dummy/vendor/assets/stylesheets/.keep +0 -0
  95. data/spec/features/javascript_spec.rb +48 -48
  96. data/spec/rails_helper.rb +4 -4
  97. data/spec/raygun/breadcrumbs/breadcrumb_spec.rb +171 -134
  98. data/spec/raygun/breadcrumbs/store_spec.rb +170 -146
  99. data/spec/raygun/raygun_spec.rb +47 -47
  100. data/spec/services/apply_whitelist_filter_to_payload_spec.rb +251 -251
  101. data/spec/spec_helper.rb +24 -24
  102. data/spec/support/fake_logger.rb +17 -17
  103. data/test/integration/client_test.rb +19 -19
  104. data/test/test_helper.rb +72 -72
  105. data/test/unit/affected_user_test.rb +136 -136
  106. data/test/unit/client_test.rb +792 -790
  107. data/test/unit/configuration_test.rb +206 -206
  108. data/test/unit/raygun_test.rb +25 -25
  109. data/test/unit/resque_failure_test.rb +24 -24
  110. data/test/unit/sidekiq_failure_test.rb +32 -32
  111. metadata +42 -45
  112. data/spec/dummy/.ruby-version +0 -1
  113. data/spec/dummy/app/assets/javascripts/cable.js +0 -13
  114. data/spec/dummy/app/channels/application_cable/channel.rb +0 -4
  115. data/spec/dummy/app/channels/application_cable/connection.rb +0 -4
  116. data/spec/dummy/app/jobs/application_job.rb +0 -2
  117. data/spec/dummy/app/mailers/application_mailer.rb +0 -4
  118. data/spec/dummy/app/models/application_record.rb +0 -3
  119. data/spec/dummy/app/views/layouts/mailer.html.erb +0 -13
  120. data/spec/dummy/app/views/layouts/mailer.text.erb +0 -1
  121. data/spec/dummy/bin/update +0 -31
  122. data/spec/dummy/bin/yarn +0 -11
  123. data/spec/dummy/config/cable.yml +0 -10
  124. data/spec/dummy/config/initializers/application_controller_renderer.rb +0 -8
  125. data/spec/dummy/config/initializers/content_security_policy.rb +0 -25
  126. data/spec/dummy/config/puma.rb +0 -34
  127. data/spec/dummy/config/spring.rb +0 -6
  128. data/spec/dummy/config/storage.yml +0 -34
  129. data/spec/dummy/db/schema.rb +0 -15
  130. data/spec/dummy/package.json +0 -5
@@ -1,194 +1,194 @@
1
- module Raygun
2
- class Configuration
3
-
4
- def self.config_option(name)
5
- define_method(name) do
6
- read_value(name)
7
- end
8
-
9
- define_method("#{name}=") do |value|
10
- set_value(name, value)
11
- end
12
- end
13
-
14
- def self.proc_config_option(name)
15
- define_method(name) do |&block|
16
- set_value(name, block) unless block == nil
17
- read_value(name)
18
- end
19
-
20
- define_method("#{name}=") do |value|
21
- set_value(name, value)
22
- end
23
- end
24
-
25
- # Your Raygun API Key - this can be found on your dashboard at Raygun.io
26
- config_option :api_key
27
-
28
- # Your JS Raygun API Key - Should be different to your api_key, it's best practice to separate your errors between front end and back end.
29
- config_option :js_api_key
30
-
31
- # Your JS Raygun API Version, defaults to latest as found on https://raygun.com/raygun-providers/javascript
32
- config_option :js_api_version
33
-
34
- # Array of exception classes to ignore
35
- config_option :ignore
36
-
37
- # Version to use
38
- config_option :version
39
-
40
- # Custom Data to send with each exception
41
- proc_config_option :custom_data
42
-
43
- # Tags to send with each exception
44
- proc_config_option :tags
45
-
46
- # Logger to use when we find an exception :)
47
- config_option :logger
48
-
49
- # Should we actually report exceptions to Raygun? (Usually disabled in Development mode, for instance)
50
- config_option :enable_reporting
51
-
52
- # Failsafe logger (for exceptions that happen when we're attempting to report exceptions)
53
- config_option :failsafe_logger
54
-
55
- # Which controller method should we call to find out the affected user?
56
- config_option :affected_user_method
57
-
58
- # Mapping of methods for the affected user object - which methods should we call for user information
59
- config_option :affected_user_mapping
60
-
61
- # Which parameter keys should we filter out by default?
62
- proc_config_option :filter_parameters
63
-
64
- # Should we switch to a white listing mode for keys instead of the default blacklist?
65
- config_option :filter_payload_with_whitelist
66
-
67
- # If :filter_payload_with_whitelist is true, which keys should we whitelist?
68
- proc_config_option :whitelist_payload_shape
69
-
70
- # Hash of proxy settings - :address, :port (defaults to 80), :username and :password (both default to nil)
71
- config_option :proxy_settings
72
-
73
- # Set this to true to have raygun4ruby log the reason why it skips reporting an exception
74
- config_option :debug
75
-
76
- # Override this if you wish to connect to a different Raygun API than the standard one
77
- config_option :api_url
78
-
79
- # Should Raygun include the raw request body in the payload? This will not include
80
- # form submissions and will not be filtered by the blacklist
81
- config_option :record_raw_data
82
-
83
- # Should the exceptions to Raygun be sent asynchronously?
84
- config_option :send_in_background
85
-
86
- # How long to wait for the POST request to the API server before timing out
87
- config_option :error_report_send_timeout
88
-
89
- # Exception classes to ignore by default
90
- IGNORE_DEFAULT = ['ActiveRecord::RecordNotFound',
91
- 'ActionController::RoutingError',
92
- 'ActionController::InvalidAuthenticityToken',
93
- 'ActionDispatch::ParamsParser::ParseError',
94
- 'CGI::Session::CookieStore::TamperedWithCookie',
95
- 'ActionController::UnknownAction',
96
- 'AbstractController::ActionNotFound',
97
- 'Mongoid::Errors::DocumentNotFound']
98
-
99
- DEFAULT_FILTER_PARAMETERS = [ :password, :card_number, :cvv ]
100
-
101
- DEFAULT_WHITELIST_PAYLOAD_SHAPE_REQUEST = {
102
- hostName: true,
103
- url: true,
104
- httpMethod: true,
105
- iPAddress: true,
106
- queryString: true,
107
- headers: true,
108
- form: {}, # Set to empty hash so that it doesn't just filter out the whole thing, but instead filters out each individual param
109
- rawData: true
110
- }.freeze
111
- DEFAULT_WHITELIST_PAYLOAD_SHAPE = {
112
- machineName: true,
113
- version: true,
114
- error: true,
115
- userCustomData: true,
116
- tags: true,
117
- request: DEFAULT_WHITELIST_PAYLOAD_SHAPE_REQUEST
118
- }.freeze
119
-
120
- attr_reader :defaults
121
-
122
- def initialize
123
- @config_values = {}
124
-
125
- # set default attribute values
126
- @defaults = OpenStruct.new(
127
- ignore: IGNORE_DEFAULT,
128
- custom_data: {},
129
- tags: [],
130
- enable_reporting: true,
131
- affected_user_method: :current_user,
132
- affected_user_mapping: AffectedUser::DEFAULT_MAPPING,
133
- filter_parameters: DEFAULT_FILTER_PARAMETERS,
134
- filter_payload_with_whitelist: false,
135
- whitelist_payload_shape: DEFAULT_WHITELIST_PAYLOAD_SHAPE,
136
- proxy_settings: {},
137
- debug: false,
138
- api_url: 'https://api.raygun.io/',
139
- breadcrumb_level: :info,
140
- record_raw_data: false,
141
- send_in_background: false,
142
- error_report_send_timeout: 10
143
- )
144
- end
145
-
146
- def [](key)
147
- read_value(key)
148
- end
149
-
150
- def []=(key, value)
151
- set_value(key, value)
152
- end
153
-
154
- def silence_reporting
155
- !enable_reporting
156
- end
157
-
158
- def silence_reporting=(value)
159
- self.enable_reporting = !value
160
- end
161
-
162
- def breadcrumb_level
163
- read_value(:breadcrumb_level)
164
- end
165
-
166
- def breadcrumb_level=(value)
167
- if Raygun::Breadcrumbs::BREADCRUMB_LEVELS.include?(value)
168
- set_value(:breadcrumb_level, value)
169
- elsif read_value(:debug)
170
- Raygun.log("[Raygun.configuration] unknown breadcrumb level: #{value} not setting")
171
- end
172
- end
173
-
174
- def affected_user_identifier_methods
175
- Raygun.deprecation_warning("Please note: You should now user config.affected_user_method_mapping.Identifier instead of config.affected_user_identifier_methods")
176
- read_value(:affected_user_mapping)[:identifier]
177
- end
178
-
179
- private
180
-
181
- def read_value(name)
182
- if @config_values.has_key?(name)
183
- @config_values[name]
184
- else
185
- @defaults.send(name)
186
- end
187
- end
188
-
189
- def set_value(name, value)
190
- @config_values[name] = value
191
- end
192
-
193
- end
194
- end
1
+ module Raygun
2
+ class Configuration
3
+
4
+ def self.config_option(name)
5
+ define_method(name) do
6
+ read_value(name)
7
+ end
8
+
9
+ define_method("#{name}=") do |value|
10
+ set_value(name, value)
11
+ end
12
+ end
13
+
14
+ def self.proc_config_option(name)
15
+ define_method(name) do |&block|
16
+ set_value(name, block) unless block == nil
17
+ read_value(name)
18
+ end
19
+
20
+ define_method("#{name}=") do |value|
21
+ set_value(name, value)
22
+ end
23
+ end
24
+
25
+ # Your Raygun API Key - this can be found on your dashboard at https://app.raygun.com
26
+ config_option :api_key
27
+
28
+ # Your JS Raygun API Key - Should be different to your api_key, it's best practice to separate your errors between front end and back end.
29
+ config_option :js_api_key
30
+
31
+ # Your JS Raygun API Version, defaults to latest as found on https://raygun.com/documentation/language-guides/javascript/crash-reporting/installation/
32
+ config_option :js_api_version
33
+
34
+ # Array of exception classes to ignore
35
+ config_option :ignore
36
+
37
+ # Version to use
38
+ config_option :version
39
+
40
+ # Custom Data to send with each exception
41
+ proc_config_option :custom_data
42
+
43
+ # Tags to send with each exception
44
+ proc_config_option :tags
45
+
46
+ # Logger to use when we find an exception :)
47
+ config_option :logger
48
+
49
+ # Should we actually report exceptions to Raygun? (Usually disabled in Development mode, for instance)
50
+ config_option :enable_reporting
51
+
52
+ # Failsafe logger (for exceptions that happen when we're attempting to report exceptions)
53
+ config_option :failsafe_logger
54
+
55
+ # Which controller method should we call to find out the affected user?
56
+ config_option :affected_user_method
57
+
58
+ # Mapping of methods for the affected user object - which methods should we call for user information
59
+ config_option :affected_user_mapping
60
+
61
+ # Which parameter keys should we filter out by default?
62
+ proc_config_option :filter_parameters
63
+
64
+ # Should we switch to a white listing mode for keys instead of the default blacklist?
65
+ config_option :filter_payload_with_whitelist
66
+
67
+ # If :filter_payload_with_whitelist is true, which keys should we whitelist?
68
+ proc_config_option :whitelist_payload_shape
69
+
70
+ # Hash of proxy settings - :address, :port (defaults to 80), :username and :password (both default to nil)
71
+ config_option :proxy_settings
72
+
73
+ # Set this to true to have raygun4ruby log the reason why it skips reporting an exception
74
+ config_option :debug
75
+
76
+ # Override this if you wish to connect to a different Raygun API than the standard one
77
+ config_option :api_url
78
+
79
+ # Should Raygun include the raw request body in the payload? This will not include
80
+ # form submissions and will not be filtered by the blacklist
81
+ config_option :record_raw_data
82
+
83
+ # Should the exceptions to Raygun be sent asynchronously?
84
+ config_option :send_in_background
85
+
86
+ # How long to wait for the POST request to the API server before timing out
87
+ config_option :error_report_send_timeout
88
+
89
+ # Exception classes to ignore by default
90
+ IGNORE_DEFAULT = ['ActiveRecord::RecordNotFound',
91
+ 'ActionController::RoutingError',
92
+ 'ActionController::InvalidAuthenticityToken',
93
+ 'ActionDispatch::ParamsParser::ParseError',
94
+ 'CGI::Session::CookieStore::TamperedWithCookie',
95
+ 'ActionController::UnknownAction',
96
+ 'AbstractController::ActionNotFound',
97
+ 'Mongoid::Errors::DocumentNotFound']
98
+
99
+ DEFAULT_FILTER_PARAMETERS = [ :password, :card_number, :cvv ]
100
+
101
+ DEFAULT_WHITELIST_PAYLOAD_SHAPE_REQUEST = {
102
+ hostName: true,
103
+ url: true,
104
+ httpMethod: true,
105
+ iPAddress: true,
106
+ queryString: true,
107
+ headers: true,
108
+ form: {}, # Set to empty hash so that it doesn't just filter out the whole thing, but instead filters out each individual param
109
+ rawData: true
110
+ }.freeze
111
+ DEFAULT_WHITELIST_PAYLOAD_SHAPE = {
112
+ machineName: true,
113
+ version: true,
114
+ error: true,
115
+ userCustomData: true,
116
+ tags: true,
117
+ request: DEFAULT_WHITELIST_PAYLOAD_SHAPE_REQUEST
118
+ }.freeze
119
+
120
+ attr_reader :defaults
121
+
122
+ def initialize
123
+ @config_values = {}
124
+
125
+ # set default attribute values
126
+ @defaults = OpenStruct.new(
127
+ ignore: IGNORE_DEFAULT,
128
+ custom_data: {},
129
+ tags: [],
130
+ enable_reporting: true,
131
+ affected_user_method: :current_user,
132
+ affected_user_mapping: AffectedUser::DEFAULT_MAPPING,
133
+ filter_parameters: DEFAULT_FILTER_PARAMETERS,
134
+ filter_payload_with_whitelist: false,
135
+ whitelist_payload_shape: DEFAULT_WHITELIST_PAYLOAD_SHAPE,
136
+ proxy_settings: {},
137
+ debug: false,
138
+ api_url: 'https://api.raygun.com/',
139
+ breadcrumb_level: :info,
140
+ record_raw_data: false,
141
+ send_in_background: false,
142
+ error_report_send_timeout: 10
143
+ )
144
+ end
145
+
146
+ def [](key)
147
+ read_value(key)
148
+ end
149
+
150
+ def []=(key, value)
151
+ set_value(key, value)
152
+ end
153
+
154
+ def silence_reporting
155
+ !enable_reporting
156
+ end
157
+
158
+ def silence_reporting=(value)
159
+ self.enable_reporting = !value
160
+ end
161
+
162
+ def breadcrumb_level
163
+ read_value(:breadcrumb_level)
164
+ end
165
+
166
+ def breadcrumb_level=(value)
167
+ if Raygun::Breadcrumbs::BREADCRUMB_LEVELS.include?(value)
168
+ set_value(:breadcrumb_level, value)
169
+ elsif read_value(:debug)
170
+ Raygun.log("[Raygun.configuration] unknown breadcrumb level: #{value} not setting")
171
+ end
172
+ end
173
+
174
+ def affected_user_identifier_methods
175
+ Raygun.deprecation_warning("Please note: You should now user config.affected_user_method_mapping.Identifier instead of config.affected_user_identifier_methods")
176
+ read_value(:affected_user_mapping)[:identifier]
177
+ end
178
+
179
+ private
180
+
181
+ def read_value(name)
182
+ if @config_values.has_key?(name)
183
+ @config_values[name]
184
+ else
185
+ @defaults.send(name)
186
+ end
187
+ end
188
+
189
+ def set_value(name, value)
190
+ @config_values[name] = value
191
+ end
192
+
193
+ end
194
+ end
data/lib/raygun/error.rb CHANGED
@@ -1,10 +1,10 @@
1
- module Raygun
2
- class Error < StandardError
3
- attr_reader :raygun_custom_data
4
-
5
- def initialize(message, raygun_custom_data = {})
6
- super(message)
7
- @raygun_custom_data = raygun_custom_data
8
- end
9
- end
10
- end
1
+ module Raygun
2
+ class Error < StandardError
3
+ attr_reader :raygun_custom_data
4
+
5
+ def initialize(message, raygun_custom_data = {})
6
+ super(message)
7
+ @raygun_custom_data = raygun_custom_data
8
+ end
9
+ end
10
+ end
@@ -1,42 +1,42 @@
1
- # Client for injecting JavaScript code for tracking front end exceptions
2
- # https://raygun.com/docs/languages/javascript
3
- module Raygun
4
- class JavaScriptTracker
5
- def head_html
6
- return unless js_api_key?
7
- [
8
- '<script type="text/javascript">',
9
- '!function(a,b,c,d,e,f,g,h){a.RaygunObject=e,a[e]=a[e]||function(){',
10
- '(a[e].o=a[e].o||[]).push(arguments)},f=b.createElement(c),g=b.getElementsByTagName(c)[0],',
11
- 'f.async=1,f.src=d,g.parentNode.insertBefore(f,g),h=a.onerror,a.onerror=function(b,c,d,f,g){',
12
- 'h&&h(b,c,d,f,g),g||(g=new Error(b)),a[e].q=a[e].q||[],a[e].q.push({',
13
- 'e:g})}}(window,document,"script","//cdn.raygun.io/raygun4js/' + js_api_version + 'raygun.min.js","rg4js");',
14
- '</script>'
15
- ].join('').html_safe
16
- end
17
-
18
- def body_html
19
- return unless js_api_key?
20
- [
21
- '<script type="text/javascript">',
22
- "rg4js('apiKey', '#{js_api_key}');",
23
- "rg4js('enableCrashReporting', true);",
24
- '</script>'
25
- ].join('').html_safe
26
- end
27
-
28
- private
29
-
30
- def js_api_key
31
- @js_api_key ||= Raygun.configuration.js_api_key
32
- end
33
-
34
- def js_api_version
35
- @js_api_version ||= Raygun.configuration.js_api_version ? "#{Raygun.configuration.js_api_version}/" : ''
36
- end
37
-
38
- def js_api_key?
39
- js_api_key.present?
40
- end
41
- end
42
- end
1
+ # Client for injecting JavaScript code for tracking front end exceptions
2
+ # https://raygun.com/docs/languages/javascript
3
+ module Raygun
4
+ class JavaScriptTracker
5
+ def head_html
6
+ return unless js_api_key?
7
+ [
8
+ '<script type="text/javascript">',
9
+ '!function(a,b,c,d,e,f,g,h){a.RaygunObject=e,a[e]=a[e]||function(){',
10
+ '(a[e].o=a[e].o||[]).push(arguments)},f=b.createElement(c),g=b.getElementsByTagName(c)[0],',
11
+ 'f.async=1,f.src=d,g.parentNode.insertBefore(f,g),h=a.onerror,a.onerror=function(b,c,d,f,g){',
12
+ 'h&&h(b,c,d,f,g),g||(g=new Error(b)),a[e].q=a[e].q||[],a[e].q.push({',
13
+ 'e:g})}}(window,document,"script","//cdn.raygun.io/raygun4js/' + js_api_version + 'raygun.min.js","rg4js");',
14
+ '</script>'
15
+ ].join('').html_safe
16
+ end
17
+
18
+ def body_html
19
+ return unless js_api_key?
20
+ [
21
+ '<script type="text/javascript">',
22
+ "rg4js('apiKey', '#{js_api_key}');",
23
+ "rg4js('enableCrashReporting', true);",
24
+ '</script>'
25
+ ].join('').html_safe
26
+ end
27
+
28
+ private
29
+
30
+ def js_api_key
31
+ @js_api_key ||= Raygun.configuration.js_api_key
32
+ end
33
+
34
+ def js_api_version
35
+ @js_api_version ||= Raygun.configuration.js_api_version ? "#{Raygun.configuration.js_api_version}/" : ''
36
+ end
37
+
38
+ def js_api_key?
39
+ js_api_key.present?
40
+ end
41
+ end
42
+ end