tackle 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +32 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +17 -0
- data/LICENSE.txt +22 -0
- data/README.md +55 -0
- data/Rakefile +12 -0
- data/lib/tackle.rb +48 -0
- data/lib/tackle/version.rb +3 -0
- data/tackle.gemspec +22 -0
- data/test/test_helper.rb +7 -0
- data/test/unit/example_test.rb +37 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d783ab0756d18bcbad3d1e148468537cfada7c16
|
4
|
+
data.tar.gz: 0e30c8381e8093ad12b02593dad55026f9b47dd5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c334d927908eb2b7e1b8dfe669992ea7bcc6069fbac642d20e8f3a71b0e80d81804b3e1cb1550d39533db176a0dc283fb66239297855b90f517450dd61180e83
|
7
|
+
data.tar.gz: bf252bfad4d2fbc4555e3540076fd61c6af9c1076298ef41823d841f1cee4fdf519959c82f6c093963e19fc43bc0aeb11e72cbd7ff47f3b606d868a38d4a9fcf
|
data/.gitignore
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
2
|
+
#
|
3
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
4
|
+
# or operating system, you probably want to add a global ignore instead:
|
5
|
+
# git config --global core.excludesfile ~/.gitignore_global
|
6
|
+
|
7
|
+
# Ignore bundler config
|
8
|
+
/.bundle
|
9
|
+
|
10
|
+
# Ignore gem files
|
11
|
+
pkg
|
12
|
+
|
13
|
+
# Ignore coverage files
|
14
|
+
/coverage
|
15
|
+
|
16
|
+
# Ignore the default SQLite database.
|
17
|
+
/db/*.sqlite3
|
18
|
+
|
19
|
+
# Ignore all logfiles and tempfiles.
|
20
|
+
/log/*.log
|
21
|
+
/tmp
|
22
|
+
|
23
|
+
# Ignore rails config
|
24
|
+
config/database.yml
|
25
|
+
config/email.yml
|
26
|
+
|
27
|
+
# Ignore generic files
|
28
|
+
*.DS_Store
|
29
|
+
*.tags*
|
30
|
+
|
31
|
+
# Ignore heroku files
|
32
|
+
/.anvil
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0-p353
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Tyler Mercier
|
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,55 @@
|
|
1
|
+
# Tackle
|
2
|
+
|
3
|
+
Ruby gem for instrumenting your code
|
4
|
+
|
5
|
+
## Status
|
6
|
+
[![Gem Version](https://badge.fury.io/rb/tackle.png)](http://badge.fury.io/rb/tackle)
|
7
|
+
[![Build Status](https://secure.travis-ci.org/tylermercier/tackle.png)](http://travis-ci.org/tylermercier/tackle)
|
8
|
+
[![Code Climate](https://codeclimate.com/github/tylermercier/tackle.png)](https://codeclimate.com/github/tylermercier/tackle)
|
9
|
+
[![Coverage Status](https://coveralls.io/repos/tylermercier/tackle/badge.png)](https://coveralls.io/r/tylermercier/tackle)
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
gem 'tackle'
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install tackle
|
24
|
+
|
25
|
+
## How to use
|
26
|
+
|
27
|
+
```
|
28
|
+
class Example
|
29
|
+
attr_reader :count
|
30
|
+
|
31
|
+
def foo(count)
|
32
|
+
@count = count
|
33
|
+
end
|
34
|
+
|
35
|
+
def bar
|
36
|
+
(1..10000).each { |i| i }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
Tackle.decorate('Example', 'foo') do
|
41
|
+
puts "META: I was called with #{@count}"
|
42
|
+
end
|
43
|
+
|
44
|
+
Tackle.time('Example', 'bar') do |t|
|
45
|
+
puts "Time elapsed #{t * 1000} milliseconds"
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
1. Fork it
|
52
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
53
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
54
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/tackle.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'benchmark'
|
2
|
+
require "tackle/version"
|
3
|
+
|
4
|
+
module Tackle
|
5
|
+
def self.decorate(class_name, method_name, &block)
|
6
|
+
klass = Kernel.const_get(class_name)
|
7
|
+
method = check_method(klass, method_name)
|
8
|
+
old_method = check_for_instrumentation(klass, method_name)
|
9
|
+
|
10
|
+
klass.class_eval do
|
11
|
+
alias_method old_method, method
|
12
|
+
|
13
|
+
define_method(method) do |*args|
|
14
|
+
send(old_method, *args)
|
15
|
+
instance_eval(&block)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.time(class_name, method_name, &block)
|
21
|
+
klass = Kernel.const_get(class_name)
|
22
|
+
method = check_method(klass, method_name)
|
23
|
+
old_method = check_for_instrumentation(klass, method_name)
|
24
|
+
|
25
|
+
klass.class_eval do
|
26
|
+
alias_method old_method, method
|
27
|
+
|
28
|
+
define_method(method) do |*args|
|
29
|
+
time = Benchmark.realtime do
|
30
|
+
send(old_method, *args)
|
31
|
+
end
|
32
|
+
block.call(time)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.check_method(klass, method_name)
|
38
|
+
method = method_name.to_sym
|
39
|
+
raise ArgumentError, "#{method} not defined on #{klass}" unless klass.instance_methods.include?(method)
|
40
|
+
method
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.check_for_instrumentation(klass, method_name)
|
44
|
+
method = "_#{method_name}".to_sym
|
45
|
+
raise ArgumentError, "#{method} already instrumented on #{klass}" if klass.instance_methods.include?(method)
|
46
|
+
method
|
47
|
+
end
|
48
|
+
end
|
data/tackle.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'tackle/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "tackle"
|
8
|
+
spec.version = Tackle::VERSION
|
9
|
+
spec.authors = ["Tyler Mercier"]
|
10
|
+
spec.email = ["tylermercier@gmail.com"]
|
11
|
+
spec.description = %q{Ruby gem for instrumenting your code}
|
12
|
+
spec.summary = %q{Ruby gem for instrumenting your code}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ExampleTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@example = Example.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_decorate
|
9
|
+
count = 0
|
10
|
+
Tackle.decorate('Example', 'foo') do
|
11
|
+
count = @count
|
12
|
+
end
|
13
|
+
@example.foo(10)
|
14
|
+
assert_equal 10, count
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_time
|
18
|
+
time = 0
|
19
|
+
Tackle.time('Example', 'bar') do |t|
|
20
|
+
time = t
|
21
|
+
end
|
22
|
+
@example.bar
|
23
|
+
assert time != 0
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Example
|
28
|
+
attr_reader :count
|
29
|
+
|
30
|
+
def foo(count)
|
31
|
+
@count = count
|
32
|
+
end
|
33
|
+
|
34
|
+
def bar
|
35
|
+
(1..10000).each { |i| i }
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tackle
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tyler Mercier
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Ruby gem for instrumenting your code
|
42
|
+
email:
|
43
|
+
- tylermercier@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- .ruby-version
|
50
|
+
- .travis.yml
|
51
|
+
- Gemfile
|
52
|
+
- Gemfile.lock
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- lib/tackle.rb
|
57
|
+
- lib/tackle/version.rb
|
58
|
+
- tackle.gemspec
|
59
|
+
- test/test_helper.rb
|
60
|
+
- test/unit/example_test.rb
|
61
|
+
homepage: ''
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 2.0.14
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: Ruby gem for instrumenting your code
|
85
|
+
test_files:
|
86
|
+
- test/test_helper.rb
|
87
|
+
- test/unit/example_test.rb
|
88
|
+
has_rdoc:
|