dustbin_lorry 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +2 -0
- data/dustbin_lorry.gemspec +29 -0
- data/lib/dustbin_lorry.rb +1 -0
- data/lib/dustbin_lorry/version.rb +3 -0
- data/lib/rack/dustbin_lorry.rb +36 -0
- data/spec/lib/rack/dustbin_lorry_spec.rb +61 -0
- data/spec/spec_helper.rb +8 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 568ac189e20ca2025554cbfe3a826ab86604ea06
|
4
|
+
data.tar.gz: 44276bcf3c6d8a08a93766dbb487e73698143509
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ffb7423628877ad045c2305c3466f757956f7610bb91203e1869baec750c995f3e437c970b5d16cb8410cddcf4682af535c292c8c71c1bc6603e4e65b5a98cab
|
7
|
+
data.tar.gz: d80d8158b65f57de5d3a7c2d169e6e71f117f8d898498aae77908fae360a5b77cd98b47999d54c57759356fb5ddcd16865f6a21f1c8ff4de88bac77420a67174
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Ian Pointer
|
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,35 @@
|
|
1
|
+
# DustbinLorry
|
2
|
+
|
3
|
+
DustinLorry: a simple Rack Middleware that dumps information about the Ruby MRI runtime (currently just if the method caches change during a Rack request).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```gem 'dustbin_lorry'```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install dustbin_lorry
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Rails
|
22
|
+
|
23
|
+
Add ```config.middleware.use 'Rack::DustbinLorry'``` to your ```config/application.rb```. The middleware will use ```Rails.Logger``` to output if any changes occur in the method caches.
|
24
|
+
|
25
|
+
### Sinatra
|
26
|
+
|
27
|
+
Add ```use DustbinLorry``` like any other Rack Middleware.
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it ( https://github.com/falloutdurham/dustbinlorry/fork )
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dustbin_lorry/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dustbin_lorry"
|
8
|
+
spec.version = DustbinLorry::VERSION
|
9
|
+
spec.authors = ["Ian Pointer"]
|
10
|
+
spec.email = ["ian@snappishproductions.com"]
|
11
|
+
spec.summary = %q{ Output method cache busts to logger }
|
12
|
+
spec.description = %q{ DustbinLorry is Rack middleware that inspects the method cache
|
13
|
+
before and after a request and will output to the logger if a change has occurred}
|
14
|
+
spec.homepage = "https://github.com/falloutdurham/dustbin_lorry"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.required_ruby_version = '>= 2.1'
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
spec.add_development_dependency "rspec-mocks"
|
28
|
+
spec.add_development_dependency "pry"
|
29
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'rack/dustbin_lorry'
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Rack
|
2
|
+
class DustbinLorry
|
3
|
+
def initialize(app)
|
4
|
+
@app = app
|
5
|
+
end
|
6
|
+
|
7
|
+
def call(env)
|
8
|
+
cache_before = RubyVM.stat
|
9
|
+
response = @app.call(env)
|
10
|
+
cache_after = RubyVM.stat
|
11
|
+
result = delta_cache(cache_before, cache_after)
|
12
|
+
logger(env).info "Method cache change: #{result}" if result.select{ |k,v| v != 0 }.any?
|
13
|
+
response
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def delta_cache(before, after)
|
19
|
+
states.each_with_object({}) do |counter, delta|
|
20
|
+
delta[counter] = after[counter] - before[counter]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def states
|
25
|
+
[:global_method_state, :global_constant_state, :class_serial]
|
26
|
+
end
|
27
|
+
|
28
|
+
def logger(env)
|
29
|
+
@logger ||= if defined?(Rails)
|
30
|
+
Rails.logger
|
31
|
+
else
|
32
|
+
env['rack.logger']
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rack::DustbinLorry do
|
4
|
+
let(:app) { double('App') }
|
5
|
+
let(:middleware) { described_class.new(app) }
|
6
|
+
|
7
|
+
context 'on no cache change' do
|
8
|
+
context 'when used without Rails' do
|
9
|
+
let(:env) { double('Rack::Env') }
|
10
|
+
let(:logger) { double('Rack::Logger') }
|
11
|
+
|
12
|
+
it 'does not log' do
|
13
|
+
expect(app).to receive(:call).with(env)
|
14
|
+
expect(env).not_to receive(:[]).with('rack.logger')
|
15
|
+
middleware.call(env)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'on cache change' do
|
21
|
+
context 'when used with Rails' do
|
22
|
+
let(:env) { double('Rack::Env') }
|
23
|
+
let(:breaking_app) { BREAK = 1 }
|
24
|
+
let(:logger) { double('Rails::Logger') }
|
25
|
+
|
26
|
+
before(:each) {
|
27
|
+
stub_const("Rails", 'Rails')
|
28
|
+
|
29
|
+
allow(app).to receive(:call).with(env) {
|
30
|
+
a = String.new
|
31
|
+
a.extend(Math)
|
32
|
+
}
|
33
|
+
expect(Rails).to receive(:logger).and_return logger
|
34
|
+
}
|
35
|
+
|
36
|
+
it 'uses the Rails logger' do
|
37
|
+
expect(logger).to receive(:info)
|
38
|
+
middleware.call(env)
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
it 'logs a change in the global_method_state' do
|
43
|
+
allow(app).to receive(:call).with(env) { Object.class_exec { def new_method; end } }
|
44
|
+
expect(logger).to receive(:info)
|
45
|
+
middleware.call(env)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'logs a change in the global_constant_state' do
|
49
|
+
allow(app).to receive(:call).with(env) { self.class.const_set :"TEST", "test" }
|
50
|
+
expect(logger).to receive(:info)
|
51
|
+
middleware.call(env)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'logs a change in the class_serial' do
|
55
|
+
allow(app).to receive(:call).with(env) { Object.class_eval "class Lorry; end" }
|
56
|
+
expect(logger).to receive(:info)
|
57
|
+
middleware.call(env)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dustbin_lorry
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ian Pointer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-24 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-mocks
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: |2-
|
84
|
+
DustbinLorry is Rack middleware that inspects the method cache
|
85
|
+
before and after a request and will output to the logger if a change has occurred
|
86
|
+
email:
|
87
|
+
- ian@snappishproductions.com
|
88
|
+
executables: []
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- ".gitignore"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- dustbin_lorry.gemspec
|
98
|
+
- lib/dustbin_lorry.rb
|
99
|
+
- lib/dustbin_lorry/version.rb
|
100
|
+
- lib/rack/dustbin_lorry.rb
|
101
|
+
- spec/lib/rack/dustbin_lorry_spec.rb
|
102
|
+
- spec/spec_helper.rb
|
103
|
+
homepage: https://github.com/falloutdurham/dustbin_lorry
|
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: '2.1'
|
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: Output method cache busts to logger
|
127
|
+
test_files:
|
128
|
+
- spec/lib/rack/dustbin_lorry_spec.rb
|
129
|
+
- spec/spec_helper.rb
|