bubot 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c1064314ec4c93d7e867557fe47933598b7a6105
4
- data.tar.gz: ccb71b09f29ec586c3a0b37a1f2d77f7762a2ae4
3
+ metadata.gz: 21a01a014424cffe08eb7b9d5981f82d1347b98c
4
+ data.tar.gz: 142d37e4b860d1517893d5aca3d68162e011079d
5
5
  SHA512:
6
- metadata.gz: eb56d4dda32148fc88d8e8bc8ff7f38d1775cadcb1309eda0ad348680cc4fbe2c27bf18d00f77d2503e72cca85f0e68244c6b876a02406753935f3f39972897f
7
- data.tar.gz: c5c90448fb55e80795fc06905f7d42df5d18192a34aab138efc5970538685adc9e879f9a59a0acf506cb55ca2a43254f3be82a66e1d1222f5767490d594a1c79
6
+ metadata.gz: a32ad5c192a105ec1ff8085b4a977f18e4d4e2024a32082342cbb180b9ce0ba0663792ff869f48804d04fa99d36f512dc26d285f3c682bbd192a308063d0e881
7
+ data.tar.gz: c76a9f3f90e26e76e0239045f9f9ba4bdab72b5fbae9d76ffda4578cdfbef7a0e4bcae018171cebc56e1e804bab7a6211634ca8d762ccbda7d3ad942da98fc2b
@@ -1 +1 @@
1
- ruby-2.0.0
1
+ ruby-2.1.1
data/README.md CHANGED
@@ -31,8 +31,6 @@ If a watched method takes longer than options[:timeout], the block will execute.
31
31
  Remember, the timeout is 0 by default so if you don't pass it a timeout, the
32
32
  block will always execute (like an after callback).
33
33
 
34
- Also, as a bonus, you get `.bubot`, which is syntactic sugar for active support callbacks.
35
-
36
34
  ### Example
37
35
 
38
36
  ```ruby
@@ -49,21 +47,6 @@ class WebAPI
49
47
  sleep 3
50
48
  "body"
51
49
  end
52
-
53
- # Syntactic sugar for active support callbacks
54
- bubot :before, :save, :udpate
55
- bubot :around, :save, ->(instance, &block) { puts "Before"; block.call; puts "All Done" }
56
- bubot :after, :save do
57
- puts "Another thing to do after"
58
- end
59
-
60
- def save
61
- puts "Saving..."
62
- end
63
-
64
- def update
65
- puts "Updating..."
66
- end
67
50
  end
68
51
  ```
69
52
 
@@ -1,63 +1,31 @@
1
1
  require "bubot/version"
2
- require "active_support/concern"
3
- require "active_support/callbacks"
4
- require "active_support/core_ext/module/aliasing"
5
2
 
6
3
  module Bubot
7
- extend ActiveSupport::Concern
8
- include ActiveSupport::Callbacks
9
4
 
10
- module ClassMethods
11
- def bubot(before_after_around, method_name, callback=nil, &block)
12
- configure_bubot method_name
13
- set_callback(method_name, before_after_around, (callback || block))
14
- end
5
+ def self.included(base)
6
+ base.extend ClassMethods
7
+ interceptor = const_set "#{base.name}Interceptor", Module.new
8
+ base.prepend interceptor
9
+ end
15
10
 
11
+ module ClassMethods
16
12
  def watch(method_name, timeout: 0, with: nil, &block)
17
- configure_bubot method_name
18
-
19
- past_time_block = with || (block if block_given?)
20
-
21
- set_callback method_name, :around, ->(instance, &block) do
22
- start_time = Time.now
23
-
24
- method_return_value = block.call
25
-
26
- if (total_time = Time.now - start_time) >= timeout
27
- past_time_block.call(self, total_time, method_return_value)
28
- end
29
- end
30
- end
13
+ interceptor = const_get "#{self.name}Interceptor"
14
+ interceptor.module_eval do
15
+ past_time_block = with || (block if block_given?)
31
16
 
32
- private
17
+ define_method(method_name) do |*args, &block|
18
+ start_time = Time.now
33
19
 
34
- def configure_bubot(method_name)
35
- method_name_with_bubot = "#{method_name}_with_bubot".to_sym
36
- return if instance_methods.include? method_name_with_bubot
20
+ method_return_value = super(*args, &block)
37
21
 
38
- define_callbacks method_name
22
+ if (total_time = Time.now - start_time) >= timeout
23
+ past_time_block.call(self, total_time, method_return_value)
24
+ end
39
25
 
40
- define_method(method_name_with_bubot) do |*args, &block|
41
- run_callbacks method_name do
42
- send("#{method_name}_without_bubot".to_sym, *args, &block)
26
+ method_return_value
43
27
  end
44
28
  end
45
-
46
- alias_method_chain_or_register_for_chaining method_name
47
- end
48
-
49
- def alias_method_chain_or_register_for_chaining(method_name)
50
- if method_defined?(method_name)
51
- alias_method_chain(method_name, :bubot)
52
- else
53
- (@method_names ||= []).push(method_name)
54
- end
55
- end
56
-
57
- def method_added(method_name)
58
- if (@method_names ||= []).delete(method_name)
59
- alias_method_chain(method_name, :bubot)
60
- end
61
29
  end
62
30
  end
63
31
  end
@@ -1,3 +1,3 @@
1
1
  module Bubot
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -6,8 +6,7 @@ end
6
6
 
7
7
  module Foo
8
8
  def not_too_slow; end
9
- def too_slow; sleep 0.006
10
- end
9
+ def too_slow; sleep 0.006 end
11
10
  end
12
11
 
13
12
  class Qux
@@ -23,40 +22,7 @@ class Qux
23
22
  end
24
23
  end
25
24
 
26
- class CallbackTester
27
- include Bubot
28
-
29
- bubot :before, :save, :update
30
- bubot :around, :save, ->(instance, &block) { instance.do_other_stuff; block.call }
31
- bubot(:after, :save) do
32
- Baz.buz
33
- end
34
-
35
- def update; end
36
- def save; end
37
- def do_other_stuff; end
38
- end
39
-
40
25
  describe Bubot do
41
- describe ".bubot" do
42
- subject(:callbacks) { CallbackTester.new }
43
- it "allows a method to be executed before another method" do
44
- expect(callbacks).to receive(:update).once
45
- callbacks.save
46
- end
47
-
48
- it "allows a block to be executed as a callback" do
49
- expect(Baz).to receive(:buz).once
50
- callbacks.save
51
- end
52
-
53
- it "allows a lambda to be executed as a callback" do
54
- expect(callbacks).to receive(:do_other_stuff).once
55
- callbacks.save
56
- end
57
-
58
- end
59
-
60
26
  describe ".watch" do
61
27
  it "calls the strategy(block) when the time exceeds the max time" do
62
28
  Baz.should_receive(:buz).once
@@ -248,15 +214,13 @@ describe Bubot do
248
214
  #something
249
215
  end
250
216
 
251
- def arguments(foo, bar)
252
- # do something
217
+ def arguments(a, b)
218
+ a + b
253
219
  end
254
220
  end
255
221
 
256
222
  original_class = OriginalArguments.new
257
- expect(original_class).to receive(:arguments_without_bubot).with("foo", "bar")
258
- original_class.arguments('foo', 'bar')
259
-
223
+ expect(original_class.arguments('foo', 'bar')).to eq('foobar')
260
224
  end
261
225
 
262
226
  it "accepts the original methods block" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bubot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Cooper
@@ -9,76 +9,76 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-31 00:00:00.000000000 Z
12
+ date: 2014-04-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ~>
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
20
  version: '1.3'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ~>
25
+ - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: '1.3'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rake
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - '>='
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '>='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rspec
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ~>
46
+ - - "~>"
47
47
  - !ruby/object:Gem::Version
48
48
  version: 2.14.1
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ~>
53
+ - - "~>"
54
54
  - !ruby/object:Gem::Version
55
55
  version: 2.14.1
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: pry
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - '>='
60
+ - - ">="
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - '>='
67
+ - - ">="
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: activesupport
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - '>='
74
+ - - ">="
75
75
  - !ruby/object:Gem::Version
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - '>='
81
+ - - ">="
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
84
  description: Take action when methods take too long
@@ -89,10 +89,10 @@ executables: []
89
89
  extensions: []
90
90
  extra_rdoc_files: []
91
91
  files:
92
- - .gitignore
93
- - .rspec
94
- - .ruby-gemset
95
- - .ruby-version
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - ".ruby-gemset"
95
+ - ".ruby-version"
96
96
  - Gemfile
97
97
  - LICENSE.txt
98
98
  - README.md
@@ -111,17 +111,17 @@ require_paths:
111
111
  - lib
112
112
  required_ruby_version: !ruby/object:Gem::Requirement
113
113
  requirements:
114
- - - '>='
114
+ - - ">="
115
115
  - !ruby/object:Gem::Version
116
116
  version: '0'
117
117
  required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  requirements:
119
- - - '>='
119
+ - - ">="
120
120
  - !ruby/object:Gem::Version
121
121
  version: '0'
122
122
  requirements: []
123
123
  rubyforge_project:
124
- rubygems_version: 2.1.11
124
+ rubygems_version: 2.2.2
125
125
  signing_key:
126
126
  specification_version: 4
127
127
  summary: Take action when methods take too long