catchex 0.0.2 → 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.
Files changed (4) hide show
  1. data/Rakefile +1 -1
  2. data/bin/rake +1 -1
  3. data/lib/catchex.rb +22 -31
  4. metadata +4 -4
data/Rakefile CHANGED
@@ -12,7 +12,7 @@ require 'rake/testtask'
12
12
  require 'fileutils'
13
13
  spec = Gem::Specification.new do |s|
14
14
  s.name = 'catchex'
15
- s.version = '0.0.2'
15
+ s.version = '0.0.3'
16
16
  s.has_rdoc = false
17
17
  s.bindir = 'bin'
18
18
  s.add_dependency('rake', '>= 0.8')
data/bin/rake CHANGED
@@ -33,6 +33,6 @@ require "catchex"
33
33
  begin
34
34
  Rake.application.run
35
35
  rescue Exception => e
36
- CatchEx.catch(e, Rake.application.name)
36
+ CatchEx.catch(e, Rake.application.top_level_tasks.first)
37
37
  raise e
38
38
  end
data/lib/catchex.rb CHANGED
@@ -6,47 +6,37 @@ module CatchEx
6
6
  require "rake"
7
7
 
8
8
  @@CATCH_EX_URL = "http://www.catchex.com"
9
- @@DATA_PUSH_URL = @@CATCH_EX_URL + "/service_ex"
10
- @@REG_HOST_URL = @@CATCH_EX_URL + "/reg_host"
9
+ @@DATA_PUSH_URL = @@CATCH_EX_URL + "/ex"
11
10
  @@PLUGIN_VERSION = "1.0"
12
11
  @@LANGUAGE = "Ruby"
13
12
 
14
- class CatchExConfig
15
- @@auth_key = ""
16
- @@host_name = ""
13
+ class Config
14
+ @@project_key = ""
15
+ @@scenario = ""
17
16
 
18
- def self.auth_key(auth_key = nil)
19
- unless auth_key.nil?
20
- @@auth_key = auth_key
17
+ def self.project_key(project_key = nil)
18
+ unless project_key.nil?
19
+ @@project_key = project_key
21
20
  else
22
- return @@auth_key
21
+ return @@project_key
23
22
  end
24
23
  end
25
24
 
26
- def self.host_name(host_name = nil)
27
- unless host_name.nil?
28
- @@host_name = host_name
25
+ def self.scenario(scenario = nil)
26
+ unless scenario.nil?
27
+ @@scenario = scenario
29
28
  else
30
- return @@host_name
29
+ return @@scenario
31
30
  end
32
31
  end
33
32
  end
34
33
 
35
34
  class << self
36
- # Register the application when the rails starts.
37
- def reg_host
38
- begin
39
- Net::HTTP.post_form(URI.parse(@@REG_HOST_URL), {:auth_key => CatchExConfig.auth_key,
40
- :host_name => CatchExConfig.host_name, :local_ip => local_ip}) if ENV['RAILS_ENV'] == 'production'
41
- rescue
42
- end
43
- end
44
35
 
45
36
  def configure
46
- yield CatchExConfig
47
- reg_host
37
+ yield Config
48
38
  end
49
-
39
+
50
40
  # Fetch the local IP address for the hosts
51
41
  def local_ip
52
42
  orig = Socket.do_not_reverse_lookup
@@ -60,11 +50,12 @@ module CatchEx
60
50
  end
61
51
 
62
52
  # The catch_ex is a convenient method for posting exception.
63
- def catch(exception, service_name = "", from = "", url = "", params = {})
53
+ def catch(exception, from = "", url = "", params = {})
54
+ return if Config.project_key.blank? || Config.scenario.blank?
64
55
  begin
65
56
  Net::HTTP.post_form(URI.parse(@@DATA_PUSH_URL), {:version => @@PLUGIN_VERSION, :language => @@LANGUAGE,
66
- :service_name => service_name, :auth_key => CatchExConfig.auth_key, :local_ip => local_ip, :message => exception.message,
67
- :stack => exception.backtrace.join("\n"), :from => from, :url => url, :params => params.inspect})
57
+ :project_key => Config.project_key, :local_ip => local_ip, :message => exception.message, :scenario => Config.scenario,
58
+ :backtrace => exception.backtrace.join("\n"), :from => from, :url => url, :params => params.inspect})
68
59
  rescue
69
60
  end
70
61
  end
@@ -77,20 +68,20 @@ module CatchEx
77
68
 
78
69
  module InstanceMethods
79
70
  def rescue_action(exception)
80
- CatchEx.catch(exception, "Rails", request.remote_ip, request.path, params) if ENV['RAILS_ENV'] == 'production' # Posting the unrescued exception to CatchEx server.
71
+ catch_ex(exception)
81
72
  super
82
73
  end
83
74
 
84
75
  # Instance method for posting the customized exception.
85
76
  def catch_ex(exception)
86
- CatchEx.catch(exception, "Rails", request.remote_ip, request.path, params) if ENV['RAILS_ENV'] == 'production'
77
+ CatchEx.catch(exception, request.remote_ip, request.url, params) if ENV['RAILS_ENV'] == 'production'
87
78
  end
88
79
  end
89
80
  end
90
81
 
91
82
  module ActionView
92
- def catchex_js app_name
93
- javascript_include_tag URI.encode("http://www.catchex.com/apps/ce?auth_key=#{CatchExConfig.auth_key}&app_name=#{app_name}")
83
+ def catchex_js
84
+ javascript_include_tag URI.encode("http://www.catchex.com/apps/ce?porject_key=#{Config.prject_key}&scenario=#{Config.scenario}")
94
85
  end
95
86
  end
96
87
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: catchex
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Braisdom
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-03 00:00:00 +08:00
18
+ date: 2011-09-20 00:00:00 +08:00
19
19
  default_executable: rake
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency