rails-middleware_timer 0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5af4d028bef60af2702af615d8e7e5e550fe6fed
4
+ data.tar.gz: 6641db589fab98a770374e4e67badd3a477c720e
5
+ SHA512:
6
+ metadata.gz: 928b3fd7b0352794facb6aef6369e66a3333081d85c6990ffa5481e079cd1e64655bf1059406a37e108fa512916f3bbf856916647d46306457353f46ab8a6f10
7
+ data.tar.gz: 7f452b990c10dbba9ec1f043aacd167378c705be0122b4a62ee4a93a1541fb1e94a3524a02d5738c879b889f7a07ef0579326457786359c6dc4a3be6b485576f
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ Gemfile.lock
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.3
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ env:
5
+ RACK_ENV: test
6
+ script:
7
+ - 'bundle exec rake'
8
+ notifications:
9
+ email:
10
+ recipients:
11
+ - humzashah+travis@gmail.com
12
+ on_success: never
13
+ on_failure: always
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+ ruby File.read('.ruby-version')
3
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Syed Humza Shah
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # MiddlewareTimer :clock1:
2
+
3
+ [![Build Status](https://travis-ci.org/humzashah/rails-middleware_timer.svg?branch=master)](https://travis-ci.org/humzashah/rails-middleware_timer)
4
+
5
+ A Rack middleware timer for Rails 4 and 5. Outputs results in miliseconds like so:
6
+
7
+ ```
8
+ Started GET "/health" for 127.0.0.1 at 2016-12-15 23:39:19 +0000
9
+ ActiveRecord::SchemaMigration Load (0.4ms) SELECT "schema_migrations".* FROM "schema_migrations"
10
+ Processing by HealthController#show as HTML
11
+ Completed 200 OK in 0ms (ActiveRecord: 0.0ms)
12
+
13
+ Sample message for Rack::Runtime ==> 22 ms
14
+ Sample message for ActionDispatch::Executor ==> 21 ms
15
+ Sample message for ActionDispatch::Static ==> 70 ms
16
+ Sample message for Rack::Sendfile ==> 70 ms
17
+ ```
18
+
19
+ ## Installation
20
+
21
+ Put the following in your Gemfile:
22
+
23
+ ```ruby
24
+ gem 'rails-middleware_timer',
25
+ git: 'git://github.com/humzashah/rails-middleware_timer.git'
26
+ ```
27
+
28
+ and `bundle install`.
29
+
30
+ Then add the following to your `environment.rb` file:
31
+
32
+ ```ruby
33
+ # config/environment.rb
34
+
35
+ # after: Rails.application.initialize!
36
+ Rails::MiddlewareTimer.time!
37
+ ```
38
+
39
+ You can use a custom message format / method like so:
40
+
41
+ ```ruby
42
+ # config/initializers/rails-middleware_timer.rb
43
+
44
+ require 'rails/middleware_timer'
45
+
46
+ module Rails
47
+ module MiddlewareTimer
48
+ module Timer
49
+ module_function
50
+
51
+ def custom_output(class_name, time_taken)
52
+ puts "Sample message for #{class_name} ==> #{time_taken}"
53
+ end
54
+ end
55
+ end
56
+ end
57
+ ```
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ t.pattern = 'test/*_test.rb'
6
+ end
7
+
8
+ task default: :test
@@ -0,0 +1,18 @@
1
+ require 'rails'
2
+ require_relative 'middleware_timer/version'
3
+ require_relative 'middleware_timer/timer'
4
+
5
+ module ::Rails
6
+ module MiddlewareTimer
7
+ module_function
8
+
9
+ def time!
10
+ ::Rails.configuration.middleware.middlewares.each do |klass|
11
+ klass = klass.name.constantize
12
+ if klass.respond_to?(:prepend)
13
+ klass.prepend(Rails::MiddlewareTimer::Timer)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,25 @@
1
+ module Rails
2
+ module MiddlewareTimer
3
+ module Timer
4
+ def call(env)
5
+ start_time = Time.now
6
+ response = super(env)
7
+ end_time = Time.now
8
+ time_taken = (1_000 * (end_time - start_time)).round
9
+ class_name = self.class.name
10
+ Rails::MiddlewareTimer::Timer.output(class_name, time_taken)
11
+ response
12
+ end
13
+
14
+ module_function
15
+
16
+ def output(class_name, time_taken)
17
+ if respond_to?(:custom_output)
18
+ custom_output(class_name, time_taken)
19
+ else
20
+ puts "#{class_name}#call took #{time_taken} ms"
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ module Rails
2
+ module MiddlewareTimer
3
+ VERSION = '0.1'
4
+ end
5
+ end
@@ -0,0 +1,22 @@
1
+ require_relative 'lib/rails/middleware_timer/version'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'rails-middleware_timer'
5
+ s.version = Rails::MiddlewareTimer::VERSION
6
+ s.date = '2016-12-15'
7
+ s.summary = 'Simple Rails middleware benchmarking'
8
+ s.description = "Time the 'call' method of the middleware classes used by Rails."
9
+ s.authors = ['Syed Humza Shah']
10
+ s.email = 'humzashah+github@gmail.com'
11
+ s.homepage = 'https://github.com/humzashah/rails-middleware_timer'
12
+ s.license = 'MIT'
13
+
14
+ s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
15
+ s.require_paths = ['lib']
16
+
17
+ s.required_ruby_version = '>= 2.2'
18
+
19
+ s.add_runtime_dependency 'rails', '>= 4.0'
20
+ s.add_development_dependency 'bundler', '>= 1.8'
21
+ s.add_development_dependency 'rake', '>= 12.0'
22
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-middleware_timer
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Syed Humza Shah
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-15 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: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '1.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '1.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '12.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '12.0'
55
+ description: Time the 'call' method of the middleware classes used by Rails.
56
+ email: humzashah+github@gmail.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - ".gitignore"
62
+ - ".ruby-version"
63
+ - ".travis.yml"
64
+ - Gemfile
65
+ - LICENSE.md
66
+ - README.md
67
+ - Rakefile
68
+ - lib/rails/middleware_timer.rb
69
+ - lib/rails/middleware_timer/timer.rb
70
+ - lib/rails/middleware_timer/version.rb
71
+ - middleware_timer.gemspec
72
+ homepage: https://github.com/humzashah/rails-middleware_timer
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '2.2'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.4.5.1
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Simple Rails middleware benchmarking
96
+ test_files: []