look_of_performance 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZTYxNTk5ZjA5ODkxY2NhNjhlZWQ3MjQyOGEzOGZjYWZmYTE3ZDdjYQ==
5
+ data.tar.gz: !binary |-
6
+ OTE2MThhMzJkMDY1NDMyYzI3NTI5NjE0YWM0MzdkYzExYjY3ZmE5MQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YzZkNmQ3MDhhMDM5NTNmODg2NDU2OTVlZDA2MTFlNDUzN2UwZjVmY2M3YWMw
10
+ OTk4OTk4ZjEwY2E2NjczNzhmNGY4Y2YzNmY4NDgzMDZlYzc0YzhhYjcwOGEz
11
+ ZWI4YjdlZDFjZDJhODRmZTI2ZGI1MzViODcwNmMxYmUxMWQzMjc=
12
+ data.tar.gz: !binary |-
13
+ ZWEzY2I0MTQwY2RkYjJhYmIyMzhkNzVhZTFiZGQ1ZGE0Y2Q2Y2E0ZjA3OGM1
14
+ Y2MzZDVlY2EwYWE4YmM4ZGNkOTdjZTljZGZmYmI1MTkzOTViMDgyYjhjMTg1
15
+ ZjIxYTcyNGU5ZmZiYWVlZWIyYzQ2YzQyNmU3NzNlNDA2ZTljZjk=
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in look_of_performance.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Jon Evans
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.
@@ -0,0 +1,77 @@
1
+ # LookOfPerformance
2
+
3
+ This gem will print out a look of disapproval in your development log when your action takes too long to process.
4
+
5
+ It's primarily an experiment into using `ActiveSupport::LogSubscriber`.
6
+
7
+ It's Rails-specific as it hooks into `ActionController`.
8
+
9
+ If you would find having `ಠ_ಠ`s thrown at you motivating, then this gem's for you.
10
+
11
+ You'll get one `ಠ_ಠ` per 100 ms that your action takes to process by default.
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'look_of_performance'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install look_of_performance
28
+
29
+ ## Usage
30
+
31
+ Add `require 'look_of_performance'` to your `ApplicationController` to get logging added to every action. Alternatively, you can just require it in specific controllers where you need motivation to improve the performance.
32
+
33
+ ## Configuration
34
+
35
+ ### Options
36
+
37
+ scolding
38
+
39
+ The string that you get once per every `limit` milliseconds.
40
+
41
+ Defaults to ಠ_ಠ
42
+
43
+ delimiter
44
+
45
+ The string that is included between each `scolding` that your slowness has earned you.
46
+
47
+ Defaults to " "
48
+
49
+ limit
50
+
51
+ The number of milliseconds you're trying to beat. If your action takes more than the `limit` to load, you'll get at least one `scolding` thrown at you. Every additional `limit` ms the response takes, you'll get an additional `scolding`.
52
+
53
+ Defaults to 100. Is that optimistic? Yeah, probably.
54
+
55
+ ### Overriding
56
+
57
+ You can override the default configuration by creating an initializer (e.g. `config/intitializers/look_of_performance.rb`) and setting the values yourself, like so:
58
+
59
+ ```ruby
60
+ LookOfPerformance::Configuration.scolding = "bananas"
61
+ ```
62
+
63
+ ## Contributing
64
+
65
+ 1. Fork it ( https://github.com/[my-github-username]/look_of_performance/fork )
66
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
67
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
68
+ 4. Push to the branch (`git push origin my-new-feature`)
69
+ 5. Create a new Pull Request
70
+
71
+ ## About Foraker Labs
72
+
73
+ <img src="http://assets.foraker.com/foraker_logo.png" width="400" height="62">
74
+
75
+ This project is maintained by Foraker Labs. The names and logos of Foraker Labs are fully owned and copyright Foraker Design, LLC.
76
+
77
+ Foraker Labs is a Boulder-based Ruby on Rails and iOS development shop. Please reach out if we can [help build your product](http://www.foraker.com).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,4 @@
1
+ require "look_of_performance/version"
2
+ require "look_of_performance/configuration"
3
+ require "look_of_performance/output"
4
+ require "look_of_performance/log_subscriber"
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+
3
+ module LookOfPerformance
4
+ module Configuration
5
+ def self.scolding
6
+ @scolding || "ಠ_ಠ"
7
+ end
8
+
9
+ def self.scolding=(scolding)
10
+ @scolding = scolding
11
+ end
12
+
13
+ def self.delimiter
14
+ @delimiter || " "
15
+ end
16
+
17
+ def self.delimiter=(delimiter)
18
+ @delimiter = delimiter
19
+ end
20
+
21
+ def self.limit
22
+ @limit || 100
23
+ end
24
+
25
+ def self.limit=(limit)
26
+ @limit = limit
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,12 @@
1
+ module LookOfPerformance
2
+ class LogSubscriber < ActiveSupport::LogSubscriber
3
+ def process_action(event)
4
+ output = Output.new(event.duration)
5
+
6
+ return unless output.sendable?
7
+ info output.to_s
8
+ end
9
+ end
10
+ end
11
+
12
+ LookOfPerformance::LogSubscriber.attach_to :action_controller
@@ -0,0 +1,36 @@
1
+ module LookOfPerformance
2
+ class Output < String
3
+ def initialize(duration, config = ::LookOfPerformance::Configuration)
4
+ self.duration = duration
5
+ self.config = config
6
+ end
7
+
8
+ def to_s
9
+ (1..times).map { |_| scolding }.join(delimiter)
10
+ end
11
+
12
+ def sendable?
13
+ duration > limit
14
+ end
15
+
16
+ private
17
+
18
+ attr_accessor :duration, :config
19
+
20
+ def times
21
+ (duration / limit).floor
22
+ end
23
+
24
+ def limit
25
+ config.limit
26
+ end
27
+
28
+ def scolding
29
+ config.scolding
30
+ end
31
+
32
+ def delimiter
33
+ config.delimiter
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module LookOfPerformance
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'look_of_performance/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "look_of_performance"
8
+ spec.version = LookOfPerformance::VERSION
9
+ spec.authors = ["Jon Evans"]
10
+ spec.email = ["jle@foraker.com"]
11
+ spec.summary = %q{Shame yourself into better performance.}
12
+ spec.description = %q{Be scolded with looks of disapproval when your app is slow.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 2.0"
24
+
25
+ spec.add_dependency "activesupport", "> 3"
26
+ end
@@ -0,0 +1,26 @@
1
+ require_relative '../../../lib/look_of_performance/configuration'
2
+
3
+ module LookOfPerformance
4
+ describe Configuration do
5
+ describe 'scolding' do
6
+ it 'can be set and retrieved' do
7
+ subject.scolding = 'bananas'
8
+ expect(subject.scolding).to eq 'bananas'
9
+ end
10
+ end
11
+
12
+ describe 'delimiter' do
13
+ it 'can be set and retrieved' do
14
+ subject.delimiter = '|'
15
+ expect(subject.delimiter).to eq '|'
16
+ end
17
+ end
18
+
19
+ describe 'limit' do
20
+ it 'can be set and retrieved' do
21
+ subject.limit = 1000
22
+ expect(subject.limit).to eq 1000
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,50 @@
1
+ require_relative '../../../lib/look_of_performance/output'
2
+ require 'ostruct'
3
+
4
+ module LookOfPerformance
5
+
6
+ TestConfig = OpenStruct.new(
7
+ scolding: 'slow',
8
+ delimiter: ' ',
9
+ limit: 100
10
+ )
11
+
12
+ describe Output do
13
+ let(:duration) { 100 }
14
+ let(:output) { described_class.new(duration, TestConfig) }
15
+
16
+ describe '#to_s' do
17
+ let(:duration) { 200 }
18
+
19
+ it 'is the output string joined by delimiter the right number of times' do
20
+ expect(output.to_s).to eq 'slow slow'
21
+ end
22
+ end
23
+
24
+ describe '#sendable?' do
25
+ context 'when duration is less than limit' do
26
+ let(:duration) { 50 }
27
+
28
+ it 'is false' do
29
+ expect(output).to_not be_sendable
30
+ end
31
+ end
32
+
33
+ context 'when duration is equal to limit' do
34
+ let(:duration) { 100 }
35
+
36
+ it 'is false' do
37
+ expect(output).to_not be_sendable
38
+ end
39
+ end
40
+
41
+ context 'when duration is greater than limit' do
42
+ let(:duration) { 150 }
43
+
44
+ it 'is true' do
45
+ expect(output).to be_sendable
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: look_of_performance
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jon Evans
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-23 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: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>'
60
+ - !ruby/object:Gem::Version
61
+ version: '3'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>'
67
+ - !ruby/object:Gem::Version
68
+ version: '3'
69
+ description: Be scolded with looks of disapproval when your app is slow.
70
+ email:
71
+ - jle@foraker.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/look_of_performance.rb
82
+ - lib/look_of_performance/configuration.rb
83
+ - lib/look_of_performance/log_subscriber.rb
84
+ - lib/look_of_performance/output.rb
85
+ - lib/look_of_performance/version.rb
86
+ - look_of_performance.gemspec
87
+ - spec/lib/look_of_performance/configuration_spec.rb
88
+ - spec/lib/look_of_performance/output_spec.rb
89
+ homepage: ''
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.2.2
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Shame yourself into better performance.
113
+ test_files:
114
+ - spec/lib/look_of_performance/configuration_spec.rb
115
+ - spec/lib/look_of_performance/output_spec.rb