toadhopper 0.9.5 → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,10 +1,5 @@
1
1
  source :gemcutter
2
2
 
3
- group :runtime do
4
- gem 'haml', '~> 2.2.0'
5
- gem 'nokogiri'
6
- end
7
-
8
3
  group :development do
9
4
  gem 'yard'
10
5
  gem 'jeweler'
@@ -12,7 +7,6 @@ end
12
7
 
13
8
  group :test do
14
9
  gem 'rake'
15
- gem 'nokogiri'
16
10
  gem 'test-unit', :require => 'test/unit'
17
11
  gem 'ruby-debug'
18
12
  end
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
- Bundler.setup(:runtime, :development, :test)
2
- Bundler.require(:runtime, :development, :test)
1
+ Bundler.setup(:development, :test)
2
+ Bundler.require(:development, :test)
3
3
 
4
4
  require 'rake/testtask'
5
5
 
data/lib/notice.erb ADDED
@@ -0,0 +1,50 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <notice version="2.0.18">
3
+ <api-key><%=h api_key %></api-key>
4
+ <notifier>
5
+ <name><%=h notifier_name %></name>
6
+ <version><%=h notifier_version %></version>
7
+ <url><%=h notifier_url %></url>
8
+ </notifier>
9
+ <error>
10
+ <class><%=h error.class.name %></class>
11
+ <message><%=h "#{error.class.name}: #{error.message}" %></message>
12
+ <backtrace>
13
+ <%- backtrace.each do |line| -%>
14
+ <line file="<%=h line.file %>" method="<%=h line.method %>" number="<%=h line.number %>" />
15
+ <%- end -%>
16
+ </backtrace>
17
+ </error>
18
+ <request>
19
+ <url><%=h url %></url>
20
+ <component><%=h component %></component>
21
+ <%- if action =~ /\S/ -%>
22
+ <action><%=h action %></action>
23
+ <%- end -%>
24
+ <%- if params && params.any? -%>
25
+ <params>
26
+ <%- params.each do |key, value| -%>
27
+ <var key="<%=h key %>"><%=h value %></var>
28
+ <%- end -%>
29
+ </params>
30
+ <%- end -%>
31
+ <%- if session && session.any? -%>
32
+ <session>
33
+ <%- session.each do |key, value| -%>
34
+ <var key="<%=h key %>"><%=h value %></var>
35
+ <%- end -%>
36
+ </session>
37
+ <%- end -%>
38
+ <%- if environment && environment.any? -%>
39
+ <cgi-data>
40
+ <%- environment.each do |key,value| -%>
41
+ <var key="<%=h key %>"><%=h value %></var>
42
+ <%- end -%>
43
+ </cgi-data>
44
+ <%- end -%>
45
+ </request>
46
+ <server-environment>
47
+ <project-root><%=h project_root %></project-root>
48
+ <environment-name><%=h framework_env %></environment-name>
49
+ </server-environment>
50
+ </notice>
data/lib/toadhopper.rb CHANGED
@@ -1,11 +1,10 @@
1
1
  require 'net/http'
2
- require 'haml'
3
- require 'haml/engine'
4
- require 'nokogiri'
2
+ require 'erb'
3
+ require 'ostruct'
5
4
 
6
5
  # Posts errors to the Hoptoad API
7
6
  class ToadHopper
8
- VERSION = "0.9.5"
7
+ VERSION = "0.9.7"
9
8
 
10
9
  # Hoptoad API response
11
10
  class Response < Struct.new(:status, :body, :errors); end
@@ -34,7 +33,7 @@ class ToadHopper
34
33
  # @option options [String] url The url for the request, required to post but not useful in a console environment
35
34
  # @option options [String] component Normally this is your Controller name in an MVC framework
36
35
  # @option options [String] action Normally the action for your request in an MVC framework
37
- # @option options [#params] request An object that response to #params and returns a hash
36
+ # @option options [Hash] params A hash of the request's parameters
38
37
  # @option options [String] notifier_name Say you're a different notifier than ToadHopper
39
38
  # @option options [String] notifier_version Specify the version of your custom notifier
40
39
  # @option options [String] notifier_url Specify the project URL of your custom notifier
@@ -69,7 +68,7 @@ class ToadHopper
69
68
  {'Content-type' => 'text/xml', 'Accept' => 'text/xml, application/xml'}.merge(headers)
70
69
  Response.new response.code.to_i,
71
70
  response.body,
72
- Nokogiri::XML.parse(response.body).xpath('//errors/error').map {|e| e.content}
71
+ response.body.scan(%r{<error>(.+)<\/error>}).flatten
73
72
  rescue TimeoutError => e
74
73
  Response.new(500, '', ['Timeout error'])
75
74
  end
@@ -78,19 +77,22 @@ class ToadHopper
78
77
 
79
78
  # @private
80
79
  def document_for(exception, options={})
81
- Haml::Engine.new(notice_template, :escape_html => true).render(Object.new, filtered_data(exception, options))
80
+ data = filtered_data(exception, options)
81
+ scope = OpenStruct.new(data).extend(ERB::Util)
82
+ ERB.new(notice_template, nil, '-').result(scope.send(:binding))
82
83
  end
83
84
 
84
- def filtered_data(exception, options)
85
+ def filtered_data(error, options)
85
86
  defaults = {
86
- :error => exception,
87
+ :error => error,
87
88
  :api_key => api_key,
88
89
  :environment => ENV.to_hash,
89
- :backtrace => exception.backtrace.map {|l| backtrace_line(l)},
90
+ :backtrace => error.backtrace.map {|l| backtrace_line(l)},
90
91
  :url => 'http://localhost/',
91
92
  :component => 'http://localhost/',
92
93
  :action => nil,
93
94
  :request => nil,
95
+ :params => nil,
94
96
  :notifier_version => VERSION,
95
97
  :notifier_url => 'http://github.com/toolmantim/toadhopper',
96
98
  :session => {},
@@ -98,11 +100,11 @@ class ToadHopper
98
100
  :project_root => Dir.pwd
99
101
  }.merge(options)
100
102
 
101
- # Filter session and environment
102
- [:session, :environment].each{|n| defaults[n] = clean(defaults[n]) if defaults[n] }
103
+ # Backwards compatibility
104
+ defaults[:params] ||= defaults[:request].params if defaults[:request]
103
105
 
104
- # Filter params
105
- defaults[:request].params = clean(defaults[:request].params) if defaults[:request] && defaults[:request].params
106
+ # Filter params, session and environment
107
+ [:params, :session, :environment].each{|n| defaults[n] = clean(defaults[n]) if defaults[n] }
106
108
 
107
109
  defaults
108
110
  end
@@ -114,7 +116,7 @@ class ToadHopper
114
116
 
115
117
  # @private
116
118
  def notice_template
117
- File.read(::File.join(::File.dirname(__FILE__), 'notice.haml'))
119
+ File.read(::File.join(::File.dirname(__FILE__), 'notice.erb'))
118
120
  end
119
121
 
120
122
  # @private
data/test/helper.rb CHANGED
@@ -1,5 +1,5 @@
1
- Bundler.setup(:runtime, :test)
2
- Bundler.require(:runtime, :test)
1
+ Bundler.setup(:test)
2
+ Bundler.require(:test)
3
3
 
4
4
  require File.expand_path("../../lib/toadhopper", __FILE__)
5
5
 
data/test/test_filters.rb CHANGED
@@ -26,12 +26,23 @@ class ToadHopper::TestFilters < Test::Unit::TestCase
26
26
  end
27
27
 
28
28
  class ToadHopper::TestCleanedOptions < Test::Unit::TestCase
29
+ def setup
30
+ @request = Struct.new(:params).new
31
+ @request.params = {:password => "foo"}
32
+ def @request.params=(*); raise NoMethodError, "requests don't have #params=, you fool"; end
33
+ @error = begin; raise "Kaboom!"; rescue => e; e end
34
+ toadhopper.filters = "password"
35
+ end
36
+
37
+ def test_filtering_params_with_backwards_compatibility
38
+ filtered_data = toadhopper.filtered_data(@error, :request => @request)[:params]
39
+
40
+ assert_equal({:password => "[FILTERED]"}, filtered_data)
41
+ end
42
+
29
43
  def test_filtering_params
30
- request = Struct.new(:params).new
31
- request.params = {:password => "foo"}
32
- error = begin; raise "Kaboom!"; rescue => e; e end
44
+ filtered_data = toadhopper.filtered_data(@error, :params => @request.params)[:params]
33
45
 
34
- toadhopper.filters = "password"
35
- assert_equal({:password => "[FILTERED]"}, toadhopper.filtered_data(error, :request => request)[:request].params)
46
+ assert_equal({:password => "[FILTERED]"}, filtered_data)
36
47
  end
37
48
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toadhopper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 0.9.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Lucas
@@ -12,29 +12,10 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2010-02-17 00:00:00 -08:00
15
+ date: 2010-02-23 00:00:00 +11:00
16
16
  default_executable:
17
- dependencies:
18
- - !ruby/object:Gem::Dependency
19
- name: haml
20
- type: :runtime
21
- version_requirement:
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ~>
25
- - !ruby/object:Gem::Version
26
- version: 2.2.0
27
- version:
28
- - !ruby/object:Gem::Dependency
29
- name: nokogiri
30
- type: :runtime
31
- version_requirement:
32
- version_requirements: !ruby/object:Gem::Requirement
33
- requirements:
34
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: "0"
37
- version:
17
+ dependencies: []
18
+
38
19
  description:
39
20
  email: t.lucas@toolmantim.com
40
21
  executables: []
@@ -51,7 +32,7 @@ files:
51
32
  - LICENSE
52
33
  - README.md
53
34
  - Rakefile
54
- - lib/notice.haml
35
+ - lib/notice.erb
55
36
  - lib/toadhopper.rb
56
37
  - test/helper.rb
57
38
  - test/test_filters.rb
data/lib/notice.haml DELETED
@@ -1,34 +0,0 @@
1
- !!!XML
2
- %notice{:version => '2.0.18'}
3
- %api-key= api_key
4
- %notifier
5
- %name= notifier_name
6
- %version= notifier_version
7
- %url= notifier_url
8
- %error
9
- %class= error.class.name
10
- %message= "#{error.class.name}: #{error.message}"
11
- %backtrace
12
- - backtrace.each do |line|
13
- %line{:method => line.method, :file => line.file, :number => line.number}/
14
- %request
15
- %url= url
16
- %component= component
17
- - if action && !action.blank?
18
- %action= action
19
- - if request && request.params.any?
20
- %params
21
- - request.params.each do |key,value|
22
- %var{:key => key}= value
23
- - if session && session.any?
24
- %session
25
- - session.each do |key,value|
26
- %var{:key => key}= value
27
- - if environment && environment.any?
28
- %cgi-data
29
- - environment.each do |key,value|
30
- %var{:key => key}= value
31
-
32
- %server-environment
33
- %project-root= project_root
34
- %environment-name= framework_env