cheaptoad 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,4 +1,10 @@
1
- === 0.0.1 2009-09-10
1
+ === 0.0.3 2009-09-16
2
+ * Added basic RSS support
3
+
4
+ === 0.0.2 2009-09-16
5
+ * Added support for viewing notices
6
+
7
+ === 0.0.1 2009-09-15
2
8
 
3
9
  * 1 major enhancement:
4
10
  * Initial release
data/Manifest.txt CHANGED
@@ -5,6 +5,13 @@ PostInstall.txt
5
5
  README.rdoc
6
6
  Rakefile
7
7
  app/controllers/notices_controller.rb
8
+ app/models/notice.rb
9
+ app/views/layouts/with_feed.html.erb
10
+ app/views/notices/index.html.erb
11
+ app/views/notices/list_by_api_key.html.erb
12
+ app/views/notices/list_notices.atom.builder
13
+ app/views/notices/list_notices.html.erb
14
+ app/views/notices/show.html.erb
8
15
  generators/cheaptoad_migration/USAGE
9
16
  generators/cheaptoad_migration/cheaptoad_migration_generator.rb
10
17
  generators/cheaptoad_migration/templates/20090914074933_ct_migrate.rb
data/README.rdoc CHANGED
@@ -16,25 +16,47 @@ app a HopToad server in just a couple of lines!
16
16
  == SYNOPSIS:
17
17
 
18
18
  Make a Rails app, or choose an existing one. In config/environment.rb,
19
- add the line "config.cheaptoad".
19
+ add the line 'config.gem "cheaptoad"'. Now, that app can receive
20
+ HopToad errors! If you want it to give you an RSS feed of errors (who
21
+ wouldn't?), you'll also need to go into config/routes.rb and add the
22
+ line "resources :notices".
20
23
 
21
- Then, create a file called config/initializers/hoptoad.rb:
24
+ In any and all apps that you want to send errors to your app, create a
25
+ file called config/initializers/hoptoad.rb, as you always would when
26
+ using HopToad. Install the HopToad notifier also, of course. The config
27
+ file will look a bit like this:
22
28
 
23
29
  HoptoadNotifier.configure do |config|
24
30
  config.api_key = 'My Project Name'
25
- config.host = 'myapp.host.com'
31
+ config.host = 'mycheaptoadapp.host.com'
26
32
  config.port = 3000
27
33
 
28
34
  config.environment_filters << "MY_SECRET_KEY"
29
35
 
30
36
  end
31
37
 
38
+ Note that the host and port are for the app that will *receive* HopToad
39
+ errors, the app you added the 'config.gem "cheaptoad"' to.
40
+
32
41
  == REQUIREMENTS:
33
42
 
34
43
  You'll need a Rails app, which will be your CheapToad server. It can do
35
44
  whatever else you like, but its notices controller (by default
36
45
  "/notices") will be used for CheapToad stuff.
37
46
 
47
+ You will *not* need a HopToad API key. That's kind of the point of this
48
+ project. Instead of using a big hexadecimal string as your API key, I
49
+ recommend you use a simple string like "My Blog" or "Secret Project X".
50
+
51
+ == RESKINNING:
52
+
53
+ By default, CheapToad has a built-in set of HTML and RSS files to give
54
+ a very simple list of your errors. If you'd rather use your own, it's
55
+ probably easiest to just build your own notices_controller.rb file and
56
+ appropriate view files to go with it. You can look at the ones in
57
+ your local copy of the CheapToad gem to do it -- they're really quite
58
+ simple. Then, add your own new HTML, CSS and whatnot to pretty it up.
59
+
38
60
  == INSTALL:
39
61
 
40
62
  sudo gem install cheaptoad
@@ -1,15 +1,24 @@
1
1
  class NoticesController < ApplicationController
2
2
  def index
3
- notice = YAML.load(request.raw_post)['notice']
4
- logger.info "Received post: #{request.raw_post}"
5
- logger.info "Received notice: #{notice.inspect}"
6
- #error_class = notice['error_class']
7
- #error_message = notice['error_message']
8
- #backtrace = notice['back'].blank? : notice['backtrace'] : notice['back']
9
- #sess = notice['session']
10
- #envir = notice['environment']
3
+ if request.put? or request.post?
4
+ notice = Notice.create_from_yaml(request.raw_post)
5
+ notice.save!
11
6
 
12
- render :nothing => true
7
+ render :text => "Successfully received error from hoptoad_notifier!"
8
+ elsif params[:api_key]
9
+ @api_key = params[:api_key]
10
+ @notices = Notice.find_all_by_api_key(@api_key)
11
+ render :layout => "with_feed", :action => "list_notices"
12
+ else
13
+ # List API keys
14
+ res = Notice.connection.execute("SELECT DISTINCT api_key FROM notices")
15
+ @keys = res.map {|i| i["api_key"]}
16
+ render :action => "list_by_api_key"
17
+ end
18
+ end
19
+
20
+ def show
21
+ @notice = Notice.find(params[:id])
13
22
  end
14
23
 
15
24
  end
@@ -0,0 +1,14 @@
1
+ class Notice < ActiveRecord::Base
2
+ [:session, :request, :environment, :backtrace].each {|a| serialize a}
3
+
4
+ def self.create_from_yaml(str)
5
+ full_yaml = YAML.load(str) if str.kind_of? String
6
+ full_yaml = full_yaml['notice'] if full_yaml['notice']
7
+
8
+ notice = Notice.create(full_yaml)
9
+ notice.backtrace_digest = Digest::SHA1.hexdigest(notice.backtrace)
10
+
11
+ notice
12
+ end
13
+
14
+ end
@@ -0,0 +1,5 @@
1
+ <head>
2
+ <%= auto_discovery_link_tag :atom, notices_url(:format => :atom, :api_key => @api_key) %>
3
+ <body>
4
+ <%= yield %>
5
+ </body>
@@ -0,0 +1,4 @@
1
+ <p>
2
+ You shouldn't see this page unless you manually go to index.html here.
3
+ Maybe you want <a href="list_notices.html">this page</a>?
4
+ </p>
@@ -0,0 +1,7 @@
1
+ <h1> CheapToad Projects (API Keys) </h1>
2
+
3
+ <ul>
4
+ <% @keys.each do |k| %>
5
+ <li> <%= link_to(k, :action => 'index', :api_key => k) -%> </li>
6
+ <% end %>
7
+ </ul>
@@ -0,0 +1,18 @@
1
+ atom_feed do |feed|
2
+ feed.title(@feedtitle || "Error Feed from CheapToad")
3
+ feed.updated(@notices.first.created_at)
4
+
5
+ @notices.each do |notice|
6
+ feed.entry(notice) do |entry|
7
+ entry.title(notice.error_message)
8
+ entry.content(<<END ,
9
+ <b>Project/APIkey:</b> #{notice.api_key} <br/>
10
+
11
+ <b>Error location:</b> #{notice.backtrace[0]} <br/>
12
+
13
+ <b>Request:</b> #{simple_format notice.request.to_yaml}
14
+ END
15
+ :type => 'html')
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ <h1> CheapToad Notices (errors) for Project <%= @api_key %> </h1>
2
+
3
+ <h2> Your errors: </h2>
4
+
5
+ <ul>
6
+ <% (@notices || []).each do |n| %>
7
+ <li> <%= link_to(n.error_message, :action => 'show', :id => n.id) %> </li>
8
+ <% end %>
9
+ </ul>
@@ -0,0 +1,20 @@
1
+ <h1> Notice: <%= @notice.error_message %> </h1>
2
+ <h3> Project (API_key): <%= @notice.api_key %> </h3>
3
+
4
+ <hr />
5
+
6
+ <h2> Request </h2>
7
+
8
+ <%= simple_format @notice.request.to_yaml %>
9
+
10
+ <h2> Backtrace </h2>
11
+
12
+ <%= simple_format @notice.backtrace.to_yaml %>
13
+
14
+ <h2> Session Info </h2>
15
+
16
+ <%= simple_format @notice.session.to_yaml %>
17
+
18
+ <h2> Environment Variables </h2>
19
+
20
+ <%= simple_format @notice.environment.to_yaml %>
@@ -1,45 +1,23 @@
1
- class AddBasicRoom < ActiveRecord::Migration
1
+ class CtMigrate < ActiveRecord::Migration
2
2
  def self.up
3
- create_table "basic_objects", :force => true do |t|
4
- t.string :name, :limit => 80
5
- t.string :type, :limit => 80
3
+ create_table "notices", :force => true do |t|
4
+ t.string :api_key, :limit => 100
5
+ t.string :error_message, :limit => 200
6
+ t.string :error_class, :limit => 100
7
+ t.string :backtrace_digest, :limit => 256
8
+ t.text :session
9
+ t.text :request
10
+ t.text :environment
11
+ t.text :backtrace
6
12
 
7
- t.string :base_description, :limit => 240
8
-
9
- # These are used for serialized fields
10
- t.text :tags
11
- t.text :descriptions
12
-
13
- t.timestamps
14
- end
15
-
16
- create_table "basic_exits", :force => true do |t|
17
- t.integer :basic_object_id, :null => false
18
- t.integer :destination_id, :null => false
19
- t.string :type, :limit => 80
20
- t.string :name, :limit => 80
21
- t.string :description, :limit => 240
22
- t.text :tags
23
13
  t.timestamps
24
14
  end
25
15
 
26
- create_table "basic_mobiles", :force => true do |t|
27
- t.integer :current_room_id
28
- t.integer :current_body_id
29
- t.string :name, :limit => 80
30
- t.string :type, :limit => 80
31
-
32
- # Serialized fields
33
- t.text :tags
34
- t.text :descriptions
35
-
36
- t.timestamps
37
- end
16
+ add_index("notices", "backtrace_digest")
38
17
  end
39
18
 
40
19
  def self.down
41
- drop_table "basic_objects"
42
- drop_table "basic_exits"
43
- drop_table "basic_mobiles"
20
+ drop_table "notices"
21
+ remove_index("notices", "backtrace_digest")
44
22
  end
45
23
  end
data/lib/cheaptoad.rb CHANGED
@@ -2,5 +2,5 @@ $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  module Cheaptoad
5
- VERSION = '0.0.1'
5
+ VERSION = '0.0.3'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cheaptoad
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noah Gibbs
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-15 00:00:00 -07:00
12
+ date: 2009-10-21 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -53,6 +53,13 @@ files:
53
53
  - README.rdoc
54
54
  - Rakefile
55
55
  - app/controllers/notices_controller.rb
56
+ - app/models/notice.rb
57
+ - app/views/layouts/with_feed.html.erb
58
+ - app/views/notices/index.html.erb
59
+ - app/views/notices/list_by_api_key.html.erb
60
+ - app/views/notices/list_notices.atom.builder
61
+ - app/views/notices/list_notices.html.erb
62
+ - app/views/notices/show.html.erb
56
63
  - generators/cheaptoad_migration/USAGE
57
64
  - generators/cheaptoad_migration/cheaptoad_migration_generator.rb
58
65
  - generators/cheaptoad_migration/templates/20090914074933_ct_migrate.rb