bubot 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ffb70ca69b74a4877180a5b9744f5898f9b992ea
4
+ data.tar.gz: 66d101334c85204bc981a50c1cf8a1a3b1fbe39c
5
+ SHA512:
6
+ metadata.gz: 3a90de6794daed69b791cecb1a9d964f4aec80bfa0473255a5d18414cf8838f6c418673384061756206eaee61958ccb2c2d88512c812446a0c3e9f1a57145260
7
+ data.tar.gz: 0e277e45f5acdc93db180080e1aa98f97616b52352fc3e7d6b394011ecc4e4199fa2b00dd7291a79f3662376ac833cf177925c5facadff229f2370296027c8dc
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1 @@
1
+ bubot
@@ -0,0 +1 @@
1
+ ruby-2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bubot.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Hashrocket
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,37 @@
1
+ # Bubot
2
+
3
+ Take action when methods take too long
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'bubot'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install bubot
18
+
19
+ ## Usage
20
+
21
+ Extend Bubot in your class.
22
+
23
+ This gives you the class method `.watch(:method_name, threshold)`.
24
+
25
+ If a watched method takes longer than the specified amount of time (threshold), the block will execute.
26
+
27
+ ```ruby
28
+ class Foo
29
+ extend Bubot
30
+
31
+ watch(:bar, 1) { run_some_code }
32
+
33
+ def bar
34
+ sleep 1.1
35
+ end
36
+ end
37
+ ```
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bubot/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bubot"
8
+ spec.version = Bubot::VERSION
9
+ spec.authors = ["Micah Cooper", "Micah Woods"]
10
+ spec.email = ["mrmicahcooper@gmail.com", "micahwoods@gmail.com"]
11
+ spec.description = %q{Take action when methods take too long}
12
+ spec.summary = %q{Take action when methods take too long}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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
+ spec.add_development_dependency "rspec", "~> 2.14.1"
23
+ spec.add_development_dependency "pry"
24
+ end
@@ -0,0 +1,39 @@
1
+ require "bubot/version"
2
+
3
+ module Bubot
4
+
5
+ def watch(method_name, timeout, &block)
6
+ define_method("#{method_name}_with_feature") do
7
+ start_time = Time.now
8
+ response = send("#{method_name}_without_feature".to_sym)
9
+ if (Time.now - start_time) > timeout
10
+ block.call(self)
11
+ end
12
+ response
13
+ end
14
+
15
+ alias_method_chain_or_register(method_name)
16
+ end
17
+
18
+ private
19
+
20
+ def alias_method_chain_or_register(method_name)
21
+ if method_defined?(method_name)
22
+ alias_method_chain(method_name)
23
+ else
24
+ (@method_names ||= []).push(method_name)
25
+ end
26
+ end
27
+
28
+ def method_added(method_name)
29
+ if (@method_names ||= []).delete(method_name)
30
+ alias_method_chain(method_name)
31
+ end
32
+ end
33
+
34
+ def alias_method_chain(method_name)
35
+ alias_method "#{method_name}_without_feature".to_sym, method_name
36
+ alias_method method_name, "#{method_name}_with_feature".to_sym
37
+ end
38
+
39
+ end
@@ -0,0 +1,3 @@
1
+ module Bubot
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,97 @@
1
+ require 'bubot'
2
+
3
+ module Baz
4
+ def self.buz; end
5
+ end
6
+
7
+ module Foo
8
+ def not_too_slow; end
9
+ def too_slow; sleep 0.006
10
+ end
11
+ end
12
+
13
+ class Qux
14
+ include Foo
15
+ extend Bubot
16
+
17
+ watch :not_too_slow, 0.005 do
18
+ Baz.buz
19
+ end
20
+
21
+ watch :too_slow, 0.005 do
22
+ Baz.buz
23
+ end
24
+ end
25
+
26
+ describe Bubot do
27
+ describe ".watch" do
28
+ it "calls the strategy(block) when the time exceeds the max time" do
29
+ Baz.should_receive(:buz).once
30
+ Qux.new.too_slow
31
+ end
32
+
33
+ it "doesn't call the strategy(block) when the time is less than the max time" do
34
+ Baz.should_not_receive(:buz)
35
+ Qux.new.not_too_slow
36
+ end
37
+
38
+ context "order doesn't matter" do
39
+
40
+ it "watch is before the method" do
41
+ class Before
42
+ extend Bubot
43
+ watch(:next_method, 0.001) { Baz.buz }
44
+ def next_method; sleep 0.002; end
45
+ end
46
+
47
+ Baz.should_receive(:buz).once
48
+ Before.new.next_method
49
+ end
50
+
51
+ it "watch is after the method" do
52
+ class After
53
+ extend Bubot
54
+ def previous_method; sleep 0.002; end
55
+ watch(:previous_method, 0.001) { Baz.buz }
56
+ end
57
+
58
+ Baz.should_receive(:buz).once
59
+ After.new.previous_method
60
+ end
61
+ end
62
+
63
+ context "watching methods that are not defined" do
64
+ it "does nothing and does not break" do
65
+ expect do
66
+ class MethodDoesNotExist
67
+ extend Bubot
68
+ watch(:dont_exist, 0.001) { Baz.buz }
69
+ end
70
+ end.not_to raise_error
71
+ end
72
+ end
73
+
74
+ context "do defining new methods" do
75
+ it "passes its instance to the strategy" do
76
+ class RecievesSelfStrategy
77
+ def self.execute(instance)
78
+ # do stuff
79
+ end
80
+ end
81
+
82
+ class PassesSelf
83
+ extend Bubot
84
+ watch(:pass_self, 0.001) do |instance|
85
+ RecievesSelfStrategy.execute(instance)
86
+ end
87
+ def pass_self; sleep 0.002; end
88
+ end
89
+
90
+ bubot_observed = PassesSelf.new
91
+ RecievesSelfStrategy.should_receive(:execute).with(bubot_observed).once
92
+
93
+ bubot_observed.pass_self
94
+ end
95
+ end
96
+ end
97
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bubot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Micah Cooper
8
+ - Micah Woods
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1.3'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '1.3'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: 2.14.1
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 2.14.1
56
+ - !ruby/object:Gem::Dependency
57
+ name: pry
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ description: Take action when methods take too long
71
+ email:
72
+ - mrmicahcooper@gmail.com
73
+ - micahwoods@gmail.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - .gitignore
79
+ - .rspec
80
+ - .ruby-gemset
81
+ - .ruby-version
82
+ - Gemfile
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bubot.gemspec
87
+ - lib/bubot.rb
88
+ - lib/bubot/version.rb
89
+ - spec/bubot_spec.rb
90
+ homepage: ''
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.0.0
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Take action when methods take too long
114
+ test_files:
115
+ - spec/bubot_spec.rb