hooks 0.3.5 → 0.3.6

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: 667b11cabf0e31ce6915b5acedc3f6bb33547307
4
- data.tar.gz: 14d261838dbcb5f189efc8dc9222133bf384c992
3
+ metadata.gz: 3d492829007f205fe193790c8ffb3f1357dc0e3e
4
+ data.tar.gz: c91b0ddaba7851ba19f668987d8f2b3e3fc16592
5
5
  SHA512:
6
- metadata.gz: 2c003d89f6509c22384807e98e18ea95e4a73f36924dc629b6e20d238a5ce5e67dc280dcd8002d7b286d0d5ddf92bee9a9ee9aee19c44fe50eb1e1063027bcc3
7
- data.tar.gz: 55070c29fa509cc6dab3cac0c35b9a717ffe6ffbbecc9168c6f042fdc6c762158e3a7a3bcb232fe5a4321330d32b9ce89e1389ba373e6dde989292c0155c251c
6
+ metadata.gz: 2663911770685b2657e4e31e2a09781e060668bc8b2ba49294e02a35591b071d7a456b2e9ce42aaee954b0fa50e8dfd382618962d89344438842650066c0094e
7
+ data.tar.gz: 79f902652386af0c587b3c147010622190b3030b42c6733dafc97294610993c4afeee41c578c13ab2f28a554db96d2880b6edf89d3846a5152b73ad15c8f9ddc
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.3.6
2
+
3
+ * Use `Uber::Options::Value` for evaluating callbacks, now that we have that gem.
4
+
1
5
  ## 0.3.5
2
6
 
3
7
  * Fixing bug where `uninitialized constant Hooks` was thrown when using InheritableAttribute exclusively. Thanks to @haswalt for reporting.
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
  s.license = 'MIT'
21
21
 
22
- s.add_dependency "uber", "~> 0.0.2"
22
+ s.add_dependency "uber", "~> 0.0.4"
23
23
 
24
24
  s.add_development_dependency "minitest", ">= 5.0.0"
25
25
  s.add_development_dependency "rake"
@@ -111,6 +111,7 @@ module Hooks
111
111
  self.class.run_hook_for(name, self, *args)
112
112
  end
113
113
 
114
+
114
115
  class HookSet < Hash
115
116
  def [](name)
116
117
  super(name.to_sym)
@@ -1,3 +1,5 @@
1
+ require 'uber/options'
2
+
1
3
  module Hooks
2
4
  class Hook < Array
3
5
  def initialize(options)
@@ -42,13 +44,13 @@ module Hooks
42
44
  end
43
45
  end
44
46
 
47
+ def <<(callback)
48
+ super Uber::Options::Value.new(callback, :dynamic => true) # allows string and symbol method names.
49
+ end
50
+
45
51
  private
46
52
  def execute_callback(scope, callback, *args)
47
- if callback.kind_of?(Symbol)
48
- scope.send(callback, *args)
49
- else
50
- scope.instance_exec(*args, &callback)
51
- end
53
+ callback.evaluate(scope, *args) # from Uber::Options::Value.
52
54
  end
53
55
 
54
56
  def continue_execution?(result)
@@ -1,3 +1,3 @@
1
1
  module Hooks
2
- VERSION = "0.3.5"
2
+ VERSION = "0.3.6"
3
3
  end
@@ -7,7 +7,7 @@ class HookTest < MiniTest::Spec
7
7
  subject << :play_music
8
8
  subject << :drink_beer
9
9
 
10
- subject.to_a.must_equal [:play_music, :drink_beer]
10
+ subject.to_a.map(&:to_sym).must_equal [:play_music, :drink_beer]
11
11
  end
12
12
  end
13
13
 
@@ -22,7 +22,7 @@ class HooksTest < MiniTest::Spec
22
22
  it "respond to Class.callbacks_for_hook" do
23
23
  assert_equal [], klass.callbacks_for_hook(:after_eight)
24
24
  klass.after_eight :dine
25
- assert_equal [:dine], klass.callbacks_for_hook(:after_eight)
25
+ assert_equal [:dine], klass.callbacks_for_hook(:after_eight).map(&:to_sym)
26
26
  end
27
27
 
28
28
  it 'symbolizes strings when defining a hook' do
@@ -41,19 +41,19 @@ class HooksTest < MiniTest::Spec
41
41
  describe "creates a public writer for the hook that" do
42
42
  it "accepts method names" do
43
43
  klass.after_eight :dine
44
- assert_equal [:dine], klass._hooks[:after_eight]
44
+ assert_equal [:dine], klass._hooks[:after_eight].map(&:to_sym)
45
45
  end
46
46
 
47
47
  it "accepts blocks" do
48
48
  klass.after_eight do true; end
49
- assert klass._hooks[:after_eight].first.kind_of? Proc
49
+ assert klass._hooks[:after_eight].first.to_sym.kind_of? Proc
50
50
  end
51
51
 
52
52
  it "be inherited" do
53
53
  klass.after_eight :dine
54
54
  subklass = Class.new(klass)
55
55
 
56
- assert_equal [:dine], subklass._hooks[:after_eight]
56
+ assert_equal [:dine], subklass._hooks[:after_eight].map(&:to_sym)
57
57
  end
58
58
  # TODO: check if options are not shared!
59
59
  end
@@ -187,11 +187,11 @@ class HooksTest < MiniTest::Spec
187
187
  let (:subclass) { Class.new(superclass) do after_eight :have_dinner end }
188
188
 
189
189
  it "inherits callbacks from the hook" do
190
- subclass.callbacks_for_hook(:after_eight).must_equal [:take_shower, :have_dinner]
190
+ subclass.callbacks_for_hook(:after_eight).map(&:to_sym).must_equal [:take_shower, :have_dinner]
191
191
  end
192
192
 
193
193
  it "doesn't mix up superclass hooks" do
194
- subclass.superclass.callbacks_for_hook(:after_eight).must_equal [:take_shower]
194
+ subclass.superclass.callbacks_for_hook(:after_eight).map(&:to_sym).must_equal [:take_shower]
195
195
  end
196
196
  end
197
197
  end
@@ -22,7 +22,7 @@ class InstanceHooksTest < HooksTest
22
22
  klass.define_hook :after_eight
23
23
  klass.after_eight :dine
24
24
 
25
- assert_equal [:dine], subject.callbacks_for_hook(:after_eight)
25
+ assert_equal [:dine], subject.callbacks_for_hook(:after_eight).map(&:to_sym)
26
26
  end
27
27
 
28
28
  describe "#after_eight (adding callbacks)" do
@@ -32,7 +32,7 @@ class InstanceHooksTest < HooksTest
32
32
  end
33
33
 
34
34
  it "adds #after_eight hook" do
35
- assert_equal [:dine], subject.callbacks_for_hook(:after_eight)
35
+ assert_equal [:dine], subject.callbacks_for_hook(:after_eight).map(&:to_sym)
36
36
  end
37
37
 
38
38
  it "responds to #run_hook" do
@@ -1,2 +1,8 @@
1
1
  require 'minitest/autorun'
2
2
  require 'hooks'
3
+
4
+ Uber::Options::Value.class_eval do
5
+ def to_sym
6
+ @value
7
+ end
8
+ end
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.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 0.0.2
19
+ version: 0.0.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: 0.0.2
26
+ version: 0.0.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement