catscan 0.1.0

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/MIT-LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Michael de Silva
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # Catscan
2
+
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ gem 'catscan'
9
+
10
+ And then execute:
11
+
12
+ $ bundle
13
+
14
+ Or install it yourself as:
15
+
16
+ $ gem install catscan
17
+
18
+ ## Contributing
19
+
20
+ 1. Fork it
21
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
22
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
23
+ 4. Push to the branch (`git push origin my-new-feature`)
24
+ 5. Create new Pull Request
25
+
26
+ ## License
27
+
28
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Catscan'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
27
+
28
+ Bundler::GemHelper.install_tasks
29
+
@@ -0,0 +1,10 @@
1
+ module Catscan
2
+ class Scan < ActiveRecord::Base
3
+ self.table_name = "catscan_scans"
4
+
5
+ attr_accessible :klass, :entity, :comment, :category,
6
+ :error_message,
7
+ :error_class,
8
+ :error_backtrace
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ class CreateCatscanScans < ActiveRecord::Migration
2
+ def change
3
+ create_table :catscan_scans do |t|
4
+ t.string :klass
5
+ t.text :payload
6
+ t.string :comment
7
+
8
+ t.integer :version, :default => 1
9
+
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ class AddExtraColumnsToCatscanScans < ActiveRecord::Migration
2
+ def change
3
+ add_column :catscan_scans, :entity, :string
4
+ add_column :catscan_scans, :category, :string
5
+ add_column :catscan_scans, :error_message, :string
6
+ add_column :catscan_scans, :error_class, :string
7
+ add_column :catscan_scans, :error_backtrace, :text
8
+ remove_column :catscan_scans, :payload
9
+ end
10
+ end
data/lib/catscan.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "catscan/engine"
2
+
3
+ module Catscan
4
+ autoload :Scannable, 'catscan/scannable'
5
+ autoload :Util, 'catscan/util'
6
+ end
@@ -0,0 +1,20 @@
1
+ module Catscan
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Catscan
4
+
5
+ initializer "catscan.scanner_subscribe", :after => :load_environment_config do |app|
6
+ ActiveSupport::Notifications.subscribe 'log.scan' do |*args|
7
+ event = ActiveSupport::Notifications::Event.new(*args)
8
+ ::Catscan::Scan.create!(
9
+ :klass => event.payload[:klass_name],
10
+ :entity => event.payload[:entity].present? ? event.payload[:entity] : nil,
11
+ :comment => event.payload[:comment].present? ? event.payload[:comment] : nil,
12
+ :category => event.payload[:category],
13
+ :error_message => event.payload[:error_message].present? ? event.payload[:error_message] : nil,
14
+ :error_class => event.payload[:error_class].present? ? event.payload[:error_class] : nil,
15
+ :error_backtrace => event.payload[:error_backtrace].present? ? Util.limit_bytesize(event.payload[:error_backtrace].force_encoding("UTF-8")) : nil
16
+ )
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,57 @@
1
+ # encoding: utf-8
2
+ require 'catscan/util'
3
+
4
+ module Catscan
5
+ module Scannable
6
+
7
+ class << self
8
+ def included _klass
9
+ _klass.class_eval do
10
+ _klass.send(:extend, ClassMethods)
11
+ end
12
+ end
13
+ end
14
+
15
+ module ClassMethods
16
+
17
+ def scan(context, entity = nil, comment = nil, category = :default, &block)
18
+ klass_name = %w(Class).include?(context.class.name) ? context.name : context.class.name
19
+ comment = Util.limit_bytesize(comment.force_encoding("UTF-8")) if comment.present?
20
+
21
+ if block_given?
22
+ ActiveSupport::Notifications.instrument("log.scan",
23
+ :klass_name => klass_name,
24
+ :entity => entity.present? ? "#{entity}" : nil,
25
+ :comment => comment.present? ? "#{comment}" : nil,
26
+ :category => "#{category}") do
27
+ context.instance_eval(&block)
28
+ end
29
+ else
30
+ ActiveSupport::Notifications.instrument("log.scan",
31
+ :klass_name => klass_name,
32
+ :entity => entity.present? ? "#{entity}" : nil,
33
+ :comment => comment.present? ? "#{comment}" : nil,
34
+ :category => "#{category}"
35
+ )
36
+ end
37
+ rescue => ex
38
+ puts "Error!"
39
+
40
+ # NOTE Re-raise exception for spec purposes
41
+ raise if Rails.env.test?
42
+
43
+ ActiveSupport::Notifications.instrument("log.scan",
44
+ :klass_name => klass_name,
45
+ :entity => entity.present? ? "#{entity}" : nil,
46
+ :comment => comment.present? ? "ERROR: #{comment}" : nil,
47
+ :category => "#{category}",
48
+ :error_message => "#{ex.message}",
49
+ :error_class => "#{ex.class}",
50
+ :error_backtrace => "#{ex.backtrace}"
51
+ )
52
+ end
53
+
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+
3
+ module Catscan
4
+ module Util
5
+
6
+ class << self
7
+
8
+ # Limits the byte size of the string, by default, to (2^16 - 1),
9
+ # which is the maximum size of MySQL's TEXT data type.
10
+ #
11
+ # @return [String] limited to 65,535 bytes, by default.
12
+ # @see http://stackoverflow.com/a/12536366/495653
13
+ def limit_bytesize(str, size = 65535)
14
+ str.encoding.name == 'UTF-8' or raise ArgumentError, "str must have UTF-8 encoding"
15
+
16
+ # Change to canonical unicode form (compose any decomposed characters).
17
+ # Works only if you're using active_support
18
+ str = str.mb_chars.compose.to_s if str.respond_to?(:mb_chars)
19
+
20
+ # Start with a string of the correct byte size, but
21
+ # with a possibly incomplete char at the end.
22
+ new_str = str.byteslice(0, size)
23
+
24
+ # We need to force_encoding from utf-8 to utf-8 so ruby will re-validate
25
+ # (idea from halfelf).
26
+ until new_str[-1].force_encoding('utf-8').valid_encoding?
27
+ # remove the invalid char
28
+ new_str = new_str.slice(0..-2)
29
+ end
30
+ new_str
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module Catscan
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :catscan do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,206 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: catscan
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michael de Silva
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-12-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.15
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.15
30
+ - !ruby/object:Gem::Dependency
31
+ name: sqlite3
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: pry
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec-rails
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '2.0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '2.0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: mocha
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: guard-rspec
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: yard
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: nyan-cat-formatter
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ description: A
159
+ email:
160
+ - michael@mwdesilva.com
161
+ executables: []
162
+ extensions: []
163
+ extra_rdoc_files: []
164
+ files:
165
+ - app/models/catscan/scan.rb
166
+ - db/migrate/20131122070729_create_catscan_scans.rb
167
+ - db/migrate/20131129073921_add_extra_columns_to_catscan_scans.rb
168
+ - lib/catscan/engine.rb
169
+ - lib/catscan/scannable.rb
170
+ - lib/catscan/util.rb
171
+ - lib/catscan/version.rb
172
+ - lib/catscan.rb
173
+ - lib/tasks/catscan_tasks.rake
174
+ - MIT-LICENSE
175
+ - Rakefile
176
+ - README.md
177
+ homepage: http://mwdesilva.com
178
+ licenses:
179
+ - MIT
180
+ post_install_message:
181
+ rdoc_options: []
182
+ require_paths:
183
+ - lib
184
+ required_ruby_version: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: 1.9.3
190
+ required_rubygems_version: !ruby/object:Gem::Requirement
191
+ none: false
192
+ requirements:
193
+ - - ! '>='
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ segments:
197
+ - 0
198
+ hash: 1562943042469313175
199
+ requirements: []
200
+ rubyforge_project:
201
+ rubygems_version: 1.8.23
202
+ signing_key:
203
+ specification_version: 3
204
+ summary: A
205
+ test_files: []
206
+ has_rdoc: