hooks 0.3.2 → 0.3.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17924e6e39cc1e9257eb89343e4b714bc617c1e3
4
- data.tar.gz: c5f79d3aec15fc0ae9a6e36f11b7db3c1c35455c
3
+ metadata.gz: 0b837493d808a39dba9923d6f57b6e679df91c1c
4
+ data.tar.gz: 5ab4d80c78c0fa39946fbbfb50e255d12e4a0cdb
5
5
  SHA512:
6
- metadata.gz: 55f49769f6dd5bb4cce4dfcea66546d6681580479be431409eff36d884417898bfcf5d903d0ebed765d20fa32ca772880bc7463805ed8c55428b60b28ef97501
7
- data.tar.gz: c216a9b2d5f1b841b91c83a8cee5a20cc0425789dd95d147ef9474af389234e990d13f46e1694966a39c1eaaa9441d86aa46f1f3f1a6cce908e05f3abe3fda30
6
+ metadata.gz: 23344cb417f370797f6de7cdcc4974bba3cd958b9a4d0c90ae4a639197b9f163081819498d8349a3851376f0c1c127e42e79133b1e6e9b5d9d3128d2f872136e
7
+ data.tar.gz: 9dacc24205cd2ecabc682c5fe5654d8119b2d4a123fe8095753696ddcf168817d7e578b34abe68f0a5759067f5dfe7f3f9ced4fb671ff4da9788a6f71eff7aa4
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.3.3
2
+
3
+ * Fix a bug where the hook writer method (e.g. `#after_dark`) wasn't available on the instance even when `InstanceHooks` was included.
4
+
1
5
  ## 0.3.2
2
6
 
3
7
  * Added `Hooks::InstanceHooks` to add hooks and/or callbacks on instance level. Thanks to @mpapis for that suggestion.
data/lib/hooks.rb CHANGED
@@ -77,11 +77,18 @@ module Hooks
77
77
  end
78
78
 
79
79
  def define_hook_writer(name)
80
- instance_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
80
+ instance_eval *hook_writer_args(name)
81
+ end
82
+
83
+ def hook_writer_args(name)
84
+ # DISCUSS: isn't there a simpler way to define a dynamic method? should the internal logic be handled by HooksSet instead?
85
+ str = <<-RUBY_EVAL
81
86
  def #{name}(method=nil, &block)
82
87
  _hooks[:#{name}] << (block || method)
83
88
  end
84
89
  RUBY_EVAL
90
+
91
+ [str, __FILE__, __LINE__ + 1]
85
92
  end
86
93
 
87
94
  def extract_options!(args)
@@ -2,12 +2,24 @@ module Hooks
2
2
  module InstanceHooks
3
3
  include ClassMethods
4
4
 
5
+ def run_hook(name, *args)
6
+ run_hook_for(name, self, *args)
7
+ end
8
+
9
+ private
5
10
  def _hooks
6
11
  @_hooks ||= self.class._hooks.clone # TODO: generify that with representable_attrs.
7
12
  end
8
13
 
9
- def run_hook(name, *args)
10
- run_hook_for(name, self, *args)
14
+ module ClassMethods
15
+ def define_hook_writer(name)
16
+ super
17
+ class_eval *hook_writer_args(name)
18
+ end
19
+ end
20
+
21
+ def self.included(base)
22
+ base.extend(ClassMethods)
11
23
  end
12
24
  end
13
25
  end
data/lib/hooks/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hooks
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
@@ -6,7 +6,11 @@ class InstanceHooksTest < HooksTest
6
6
  include Hooks::InstanceHooks
7
7
  end }
8
8
 
9
- subject { klass.new }
9
+ subject { klass.new.tap do |obj|
10
+ obj.instance_eval do
11
+ def dine; executed << :dine; end
12
+ end
13
+ end }
10
14
 
11
15
  it "adds hook to instance" do
12
16
  subject.define_hook :after_eight
@@ -32,9 +36,16 @@ class InstanceHooksTest < HooksTest
32
36
  end
33
37
 
34
38
  it "responds to #run_hook" do
35
- subject.instance_eval do
36
- def dine; executed << :dine; end
37
- end
39
+ subject.run_hook :after_eight
40
+ subject.executed.must_equal [:dine]
41
+ end
42
+ end
43
+
44
+ describe "#after_eight from class (no define_hook in instance)" do
45
+ it "responds to #after_eight" do
46
+ klass.define_hook :after_eight
47
+
48
+ subject.after_eight :dine
38
49
 
39
50
  subject.run_hook :after_eight
40
51
  subject.executed.must_equal [:dine]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hooks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer