aroi 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/lib/aroi.rb +4 -0
- data/lib/aroi/instrumentation/active_record.rb +46 -0
- data/lib/aroi/version.rb +3 -0
- data/spec/aroi/instrumentation/active_record_spec.rb +58 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/support/active_record.rb +15 -0
- data/test.sh +15 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2348c0ea49f0d10f06c1ff4d2550c2330a4d040e
|
4
|
+
data.tar.gz: 64783e45170a5f753e63e8ab7411def23769e727
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 46e6deea60ac9cac1b51cc99188012eaa8fa910df0cfb7c3a3c9387523fdab20fe8045e32507c128374a83ac23f2a83c827c209601979124a930d241b1687640
|
7
|
+
data.tar.gz: 5f759570091e27f832d835b731a81e5225b9fcd7c82f2b883826f129493ce1a8a31e9114297aef63c845f2263443fd619908993c4ab24b20a4621c357b6d1564
|
data/lib/aroi.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
module Aroi
|
4
|
+
module Instrumentation
|
5
|
+
|
6
|
+
def self.extended_active_record?
|
7
|
+
!!@canvas_statsd_extended_active_record
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.extended_active_record!
|
11
|
+
@canvas_statsd_extended_active_record = true
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.instrument_creation!
|
15
|
+
::ActiveRecord::Base.send(:include, Aroi::Instrumentation::ActiveRecord)
|
16
|
+
end
|
17
|
+
|
18
|
+
module ActiveRecord
|
19
|
+
|
20
|
+
def self.included(klass)
|
21
|
+
klass.class_eval do
|
22
|
+
|
23
|
+
unless Aroi::Instrumentation.extended_active_record?
|
24
|
+
self.singleton_class.send(:alias_method, :allocate_in_block, :allocate)
|
25
|
+
def klass.allocate
|
26
|
+
ActiveSupport::Notifications.instrument('instance.active_record', name: self.base_class.name) do
|
27
|
+
allocate_in_block
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
alias_method :initialize_in_block, :initialize
|
32
|
+
def initialize(*args, &block)
|
33
|
+
ActiveSupport::Notifications.instrument('instance.active_record', name: self.class.name) do
|
34
|
+
initialize_in_block(*args, &block)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
Aroi::Instrumentation.extended_active_record!
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/aroi/version.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'active_support'
|
3
|
+
|
4
|
+
class User < ActiveRecord::Base
|
5
|
+
self.table_name = 'users'
|
6
|
+
end
|
7
|
+
|
8
|
+
describe Aroi::Instrumentation do
|
9
|
+
|
10
|
+
describe '#instrument_creation!' do
|
11
|
+
it 'should set extended_active_record to true' do
|
12
|
+
Aroi::Instrumentation.instrument_creation!
|
13
|
+
expect(Aroi::Instrumentation.extended_active_record?).to eq true
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should include the ActiveRecord module for all ActiveRecord::Base objects' do
|
17
|
+
Aroi::Instrumentation.instrument_creation!
|
18
|
+
ActiveSupport::Notifications.subscribe(/instance.active_record/) do |name, start, finish, id, payload|
|
19
|
+
expect(payload[:name]).to eq "User"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
describe Aroi::Instrumentation::ActiveRecord do
|
27
|
+
|
28
|
+
before do
|
29
|
+
Aroi::Instrumentation.instrument_creation!
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#initialize' do
|
33
|
+
it 'should fire one notification for each object created' do
|
34
|
+
count = 0;
|
35
|
+
ActiveSupport::Notifications.subscribe(/instance.active_record/) do |name, start, finish, id, payload|
|
36
|
+
count += 1;
|
37
|
+
end
|
38
|
+
3.times do
|
39
|
+
User.new
|
40
|
+
end
|
41
|
+
expect(count).to eq 3
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#allocate' do
|
46
|
+
it 'should fire one notification for each ojbect allocated' do
|
47
|
+
count = 0;
|
48
|
+
ActiveSupport::Notifications.subscribe(/instance.active_record/) do |name, start, finish, id, payload|
|
49
|
+
count += 1;
|
50
|
+
end
|
51
|
+
3.times do
|
52
|
+
User.allocate
|
53
|
+
end
|
54
|
+
expect(count).to eq 3
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'aroi'
|
2
|
+
require 'support/active_record'
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
6
|
+
config.run_all_when_everything_filtered = true
|
7
|
+
config.filter_run :focus
|
8
|
+
config.color = true
|
9
|
+
|
10
|
+
config.order = 'random'
|
11
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
|
4
|
+
|
5
|
+
ActiveRecord::Migration.verbose = false
|
6
|
+
ActiveRecord::Schema.define(version: 1) do
|
7
|
+
create_table :examples, force: true do |t|
|
8
|
+
t.string :state
|
9
|
+
t.string :name
|
10
|
+
end
|
11
|
+
|
12
|
+
create_table :users, force: true do |t|
|
13
|
+
t.string :name
|
14
|
+
end
|
15
|
+
end
|
data/test.sh
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
result=0
|
3
|
+
|
4
|
+
echo "################ aroi ################"
|
5
|
+
bundle check || bundle install
|
6
|
+
bundle exec rspec spec
|
7
|
+
let result=$result+$?
|
8
|
+
|
9
|
+
if [ $result -eq 0 ]; then
|
10
|
+
echo "SUCCESS"
|
11
|
+
else
|
12
|
+
echo "FAILURE"
|
13
|
+
fi
|
14
|
+
|
15
|
+
exit $result
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aroi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jason Madsen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '4.2'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.2'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '4.2'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.5'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.5'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
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
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: sqlite3
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
description:
|
90
|
+
email:
|
91
|
+
- knomedia@gmail.com
|
92
|
+
executables: []
|
93
|
+
extensions: []
|
94
|
+
extra_rdoc_files: []
|
95
|
+
files:
|
96
|
+
- lib/aroi.rb
|
97
|
+
- lib/aroi/instrumentation/active_record.rb
|
98
|
+
- lib/aroi/version.rb
|
99
|
+
- spec/aroi/instrumentation/active_record_spec.rb
|
100
|
+
- spec/spec_helper.rb
|
101
|
+
- spec/support/active_record.rb
|
102
|
+
- test.sh
|
103
|
+
homepage: https://github.com/knomedia/aroi
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.2.2
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: 'ActiveRecord Object Instrumenter: Instrument the creation of ActiveRecord
|
127
|
+
objects'
|
128
|
+
test_files:
|
129
|
+
- spec/aroi/instrumentation/active_record_spec.rb
|
130
|
+
- spec/spec_helper.rb
|
131
|
+
- spec/support/active_record.rb
|
132
|
+
has_rdoc:
|