glitchy_gem 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :gemcutter
2
+
3
+ # Specify your gem's dependencies in bearcat_gem.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../lib/glitchy_gem/version", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "glitchy_gem"
6
+ s.version = GlitchyGem::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["GlitchyApp"]
9
+ s.email = ["support@glitchygem.com"]
10
+ s.homepage = "http://rubygems.org/gems/glitchy_gem"
11
+ s.summary = "The gem to enable you to track your application errors with GlitchApp"
12
+ s.description = "Track your application errors with GlitchyApp and search through them."
13
+
14
+ s.required_rubygems_version = ">= 1.3.6"
15
+ s.rubyforge_project = "glitchy_gem"
16
+
17
+ s.add_development_dependency "bundler", ">= 1.0.0"
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
21
+ s.require_path = 'lib'
22
+ end
@@ -0,0 +1,39 @@
1
+ module GlitchyGem
2
+ class Glitch
3
+ attr_reader :exception
4
+ def initialize(e, options = {})
5
+ @rack_env = options[:rack_env] || {}
6
+ @exception = e
7
+
8
+ params = options[:params] || @rack_env['action_dispatch.request.parameters'] || rack_env(:params)
9
+ url = options[:url] || rack_env(:url)
10
+ controller = options[:controller] || params['controller']
11
+ action = options[:action] || params['action']
12
+ session = options[:session] || @rack_env['rack.session']
13
+
14
+ @uri = URI.parse("http://#{GlitchyGem.url}/glitches?auth_token=#{GlitchyGem.api_key}")
15
+ @http = Net::HTTP.new(@uri.host, @uri.port)
16
+ @request = Net::HTTP::Post.new(@uri.request_uri)
17
+ @request["Content-Type"] = "application/json"
18
+ @request.body = { :glitch => e.to_hash.merge({ :url => url, :params => params, :controller => controller, :action => action, :session => session, :environment => GlitchyGem.environment }) }.to_json
19
+ end
20
+
21
+ def send
22
+ begin
23
+ @http.request(@request)
24
+ rescue Errno::ECONNREFUSED => e
25
+ GlitchyGem.logger.info "Failed to connect to GlitchyApp. Could not notify about the exception #{self.exception.to_hash.inspect}"
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def rack_env(method)
32
+ rack_request.send(method) if rack_request
33
+ end
34
+
35
+ def rack_request
36
+ @rack_request ||= ::Rack::Request.new(@rack_env)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,5 @@
1
+ class Exception
2
+ def to_hash
3
+ { :backtrace => backtrace, :message => message, :klass => self.class.to_s }
4
+ end
5
+ end
@@ -0,0 +1,30 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+
4
+ module GlitchyGem
5
+ class Rack
6
+ def initialize(app)
7
+ @app = app
8
+ end
9
+
10
+ def call(env)
11
+ begin
12
+ response = @app.call(env)
13
+ rescue Exception => e
14
+ send_glitch(e, env)
15
+ raise
16
+ end
17
+
18
+ if env['rack.exception']
19
+ send_glitch(env['rack.exception'], env)
20
+ end
21
+
22
+ response
23
+ end
24
+ end
25
+ end
26
+
27
+ def send_glitch(e, env)
28
+ glitch = GlitchyGem::Glitch.new(e, :rack_env => env)
29
+ glitch.send
30
+ end
@@ -0,0 +1,34 @@
1
+ module GlitchyGem
2
+ module Rails
3
+ module ActionControllerCatcher
4
+
5
+ def self.included(base) #:nodoc:
6
+ base.send(:alias_method, :rescue_action_without_glitchy, :rescue_action)
7
+ base.send(:alias_method, :rescue_action, :rescue_action_with_glitchy)
8
+ end
9
+
10
+ private
11
+
12
+ def rescue_action_with_glitchy(exception)
13
+ error_id = send_glitch(exception, req_data)
14
+ rescue_action_without_glitchy(exception)
15
+ end
16
+
17
+ def req_data
18
+ {
19
+ :params => params.to_hash,
20
+ :session => session.to_hash,
21
+ :controller => params[:controller],
22
+ :action => params[:action],
23
+ :url => "#{request.protocol}#{request.host}:#{request.port}#{request.request_uri}"
24
+ }
25
+ end
26
+
27
+ end
28
+ end
29
+ end
30
+
31
+ def send_glitch(e, req_data)
32
+ glitch = GlitchyGem::Glitch.new(e, req_data)
33
+ glitch.send
34
+ end
@@ -0,0 +1,29 @@
1
+ require 'glitchy_gem/rails/action_controller_catcher'
2
+
3
+ module GlitchyGem
4
+ module Rails
5
+ def self.initialize
6
+ if defined?(ActionController::Base)
7
+ ActionController::Base.send(:include, GlitchyGem::Rails::ActionControllerCatcher)
8
+ end
9
+
10
+ if defined?(::Rails.configuration) && ::Rails.configuration.respond_to?(:middleware)
11
+ ::Rails.configuration.middleware.insert_after 'ActionController::Failsafe', GlitchyGem::Rack
12
+ end
13
+
14
+ if defined?(::Rails.logger)
15
+ rails_logger = ::Rails.logger
16
+ elsif defined?(RAILS_DEFAULT_LOGGER)
17
+ rails_logger = RAILS_DEFAULT_LOGGER
18
+ end
19
+
20
+ GlitchyGem.configure do |config|
21
+ config.environment ||= RAILS_ENV if defined?(RAILS_ENV)
22
+ config.logger ||= rails_logger
23
+ config.url ||= "glitchyapp.com"
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ GlitchyGem::Rails.initialize
@@ -0,0 +1,17 @@
1
+ require 'rails'
2
+
3
+ module GlitchyGem
4
+ class Railtie < Rails::Railtie
5
+ initializer "glitchy.use_rack_middleware" do |app|
6
+ app.config.middleware.use "GlitchyGem::Rack"
7
+ end
8
+
9
+ config.after_initialize do
10
+ GlitchyGem.configure do |config|
11
+ config.environment ||= Rails.env
12
+ config.logger ||= Rails.logger
13
+ config.url ||= "glitchyapp.com"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module GlitchyGem
2
+ VERSION = "0.1"
3
+ end
@@ -0,0 +1,13 @@
1
+ require 'glitchy_gem/patches'
2
+ require 'glitchy_gem/glitch'
3
+ require 'glitchy_gem/rack'
4
+ require 'glitchy_gem/railtie' if defined?(Rails::Railtie)
5
+
6
+ module GlitchyGem
7
+ class << self
8
+ attr_accessor :api_key, :environment, :logger, :url
9
+ def configure
10
+ yield(self)
11
+ end
12
+ end
13
+ end
data/rails/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'glitchy_gem/rails'
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: glitchy_gem
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ version: "0.1"
10
+ platform: ruby
11
+ authors:
12
+ - GlitchyApp
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-06-18 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: bundler
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 23
29
+ segments:
30
+ - 1
31
+ - 0
32
+ - 0
33
+ version: 1.0.0
34
+ type: :development
35
+ version_requirements: *id001
36
+ description: Track your application errors with GlitchyApp and search through them.
37
+ email:
38
+ - support@glitchygem.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files: []
44
+
45
+ files:
46
+ - .gitignore
47
+ - Gemfile
48
+ - Rakefile
49
+ - glitchy_gem.gemspec
50
+ - lib/glitchy_gem.rb
51
+ - lib/glitchy_gem/glitch.rb
52
+ - lib/glitchy_gem/patches.rb
53
+ - lib/glitchy_gem/rack.rb
54
+ - lib/glitchy_gem/rails.rb
55
+ - lib/glitchy_gem/rails/action_controller_catcher.rb
56
+ - lib/glitchy_gem/railtie.rb
57
+ - lib/glitchy_gem/version.rb
58
+ - rails/init.rb
59
+ has_rdoc: true
60
+ homepage: http://rubygems.org/gems/glitchy_gem
61
+ licenses: []
62
+
63
+ post_install_message:
64
+ rdoc_options: []
65
+
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ hash: 23
83
+ segments:
84
+ - 1
85
+ - 3
86
+ - 6
87
+ version: 1.3.6
88
+ requirements: []
89
+
90
+ rubyforge_project: glitchy_gem
91
+ rubygems_version: 1.3.7
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: The gem to enable you to track your application errors with GlitchApp
95
+ test_files: []
96
+