hooks 0.3.3 → 0.3.4

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: 0b837493d808a39dba9923d6f57b6e679df91c1c
4
- data.tar.gz: 5ab4d80c78c0fa39946fbbfb50e255d12e4a0cdb
3
+ metadata.gz: 0f63910d0f878778c924a59a0de9503a56bdb748
4
+ data.tar.gz: 99e98842efad2faee958e2083101035623bae89e
5
5
  SHA512:
6
- metadata.gz: 23344cb417f370797f6de7cdcc4974bba3cd958b9a4d0c90ae4a639197b9f163081819498d8349a3851376f0c1c127e42e79133b1e6e9b5d9d3128d2f872136e
7
- data.tar.gz: 9dacc24205cd2ecabc682c5fe5654d8119b2d4a123fe8095753696ddcf168817d7e578b34abe68f0a5759067f5dfe7f3f9ced4fb671ff4da9788a6f71eff7aa4
6
+ metadata.gz: bd8cfb3df2da9db53a3ad96084f5664bb4df4918cc2bbf9328e08fa5a24685f766db913e881a68aae6d3df617850299f5af9f9322b291c5fe9b6a705c714c43b
7
+ data.tar.gz: 4f104c3b400edf21cb19523b4233b8aac411733d5c8d79b11e645f01c72d8b71019f9ee514200c7b7ac3aae714232948299e5219375661978f0eb1c590767566
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.3.4
2
+
3
+ * Removing `InheritableAttribute` as we use uber's `InheritableAttr` now.
4
+
1
5
  ## 0.3.3
2
6
 
3
7
  * Fix a bug where the hook writer method (e.g. `#after_dark`) wasn't available on the instance even when `InstanceHooks` was included.
data/README.md CHANGED
@@ -155,7 +155,7 @@ end
155
155
 
156
156
  Note that you have to include `Hooks::InstanceHooks` to get this additional functionality.
157
157
 
158
- See how callbacks can be added to a separate object, now.
158
+ Callbacks can now be added to a single object.
159
159
 
160
160
  ```ruby
161
161
  garfield = Cat.new
@@ -164,7 +164,7 @@ garfield.after_dark :sleep
164
164
  garfield.run_hook(:after_dark) # => invoke "Chase mice" hook and #sleep
165
165
  ```
166
166
 
167
- This will copy all callbacks from the `after_dark` hook to the instance and add a second hook. This all happens on the `garfield` instance, only, and leaves the class untouched.
167
+ What happens is that the `garfield` object inherits existing hooks with all their callbacks from the `Cat` class, namely, this is `:after_dark`. It can then add local callbacks (or even more hooks) to itself without affecting the `Cat` class.
168
168
 
169
169
  Naturally, adding new hooks works like-wise.
170
170
 
@@ -19,7 +19,8 @@ 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"
23
+
22
24
  s.add_development_dependency "minitest", ">= 5.0.0"
23
25
  s.add_development_dependency "rake"
24
- s.add_development_dependency "pry"
25
26
  end
@@ -1,4 +1,4 @@
1
- require "hooks/inheritable_attribute"
1
+ require "uber/inheritable_attr"
2
2
  require "hooks/hook"
3
3
 
4
4
  # Almost like ActiveSupport::Callbacks but 76,6% less complex.
@@ -20,7 +20,7 @@ require "hooks/hook"
20
20
  module Hooks
21
21
  def self.included(base)
22
22
  base.class_eval do
23
- extend InheritableAttribute
23
+ extend Uber::InheritableAttr
24
24
  extend ClassMethods
25
25
  inheritable_attr :_hooks
26
26
  self._hooks= HookSet.new
@@ -1,33 +1,5 @@
1
- module Hooks
2
- module InheritableAttribute
3
- # Creates an inheritable attribute with accessors in the singleton class. Derived classes inherit the
4
- # attributes. This is especially helpful with arrays or hashes that are extended in the inheritance
5
- # chain. Note that you have to initialize the inheritable attribute.
6
- #
7
- # Example:
8
- #
9
- # class Cat
10
- # inheritable_attr :drinks
11
- # self.drinks = ["Becks"]
12
- #
13
- # class Garfield < Cat
14
- # self.drinks << "Fireman's 4"
15
- #
16
- # and then, later
17
- #
18
- # Cat.drinks #=> ["Becks"]
19
- # Garfield.drinks #=> ["Becks", "Fireman's 4"]
20
- def inheritable_attr(name)
21
- instance_eval %Q{
22
- def #{name}=(v)
23
- @#{name} = v
24
- end
25
-
26
- def #{name}
27
- return @#{name} unless superclass.respond_to?(:#{name}) and value = superclass.#{name}
28
- @#{name} ||= value.clone # only do this once.
29
- end
30
- }
31
- end
32
- end
33
- end
1
+ require "uber/inheritable_attr"
2
+
3
+ Hooks::InheritableAttribute = Uber::InheritableAttr
4
+
5
+ warn "WARNING: Hooks::InheritableAttribute is deprecated, use Uber::InheritableAttr instead."
@@ -12,6 +12,7 @@ module Hooks
12
12
  end
13
13
 
14
14
  module ClassMethods
15
+ # Adds a hook writer to the instance in addition to the class writer.
15
16
  def define_hook_writer(name)
16
17
  super
17
18
  class_eval *hook_writer_args(name)
@@ -1,3 +1,3 @@
1
1
  module Hooks
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
@@ -50,6 +50,26 @@ class InstanceHooksTest < HooksTest
50
50
  subject.run_hook :after_eight
51
51
  subject.executed.must_equal [:dine]
52
52
  end
53
+
54
+ it "keeps hooks separate per instance" do
55
+ klass.define_hook :after_eight
56
+
57
+ other = klass.new.tap do |obj|
58
+ obj.instance_eval do
59
+ def dine_other; executed << :dine_other; end
60
+ end
61
+ end
62
+
63
+ subject.after_eight :dine
64
+ subject.run_hook :after_eight
65
+ other.after_eight :dine_other
66
+ other.run_hook :after_eight
67
+
68
+ subject.executed.must_equal [:dine]
69
+ other.executed.must_equal [:dine_other]
70
+ end
71
+
53
72
  end
73
+
54
74
  end
55
- end
75
+ end
@@ -1,3 +1,2 @@
1
1
  require 'minitest/autorun'
2
- require 'pry'
3
2
  require 'hooks'
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hooks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-06 00:00:00.000000000 Z
11
+ date: 2014-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: minitest
14
+ name: uber
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 5.0.0
20
- type: :development
19
+ version: 0.0.2
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: 5.0.0
26
+ version: 0.0.2
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 5.0.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 5.0.0
41
41
  - !ruby/object:Gem::Dependency
42
- name: pry
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: Declaratively define hooks, add callbacks and run them with the options
@@ -60,8 +60,8 @@ executables: []
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
- - .gitignore
64
- - .travis.yml
63
+ - ".gitignore"
64
+ - ".travis.yml"
65
65
  - CHANGES.md
66
66
  - Gemfile
67
67
  - LICENSE.txt
@@ -75,7 +75,6 @@ files:
75
75
  - lib/hooks/version.rb
76
76
  - test/hook_test.rb
77
77
  - test/hooks_test.rb
78
- - test/inheritable_attribute_test.rb
79
78
  - test/instance_hooks_test.rb
80
79
  - test/test_helper.rb
81
80
  homepage: http://nicksda.apotomo.de/2010/09/hooks-and-callbacks-for-ruby-but-simple/
@@ -88,18 +87,22 @@ require_paths:
88
87
  - lib
89
88
  required_ruby_version: !ruby/object:Gem::Requirement
90
89
  requirements:
91
- - - '>='
90
+ - - ">="
92
91
  - !ruby/object:Gem::Version
93
92
  version: '0'
94
93
  required_rubygems_version: !ruby/object:Gem::Requirement
95
94
  requirements:
96
- - - '>='
95
+ - - ">="
97
96
  - !ruby/object:Gem::Version
98
97
  version: '0'
99
98
  requirements: []
100
99
  rubyforge_project:
101
- rubygems_version: 2.0.3
100
+ rubygems_version: 2.2.1
102
101
  signing_key:
103
102
  specification_version: 4
104
103
  summary: Generic hooks with callbacks for Ruby.
105
- test_files: []
104
+ test_files:
105
+ - test/hook_test.rb
106
+ - test/hooks_test.rb
107
+ - test/instance_hooks_test.rb
108
+ - test/test_helper.rb
@@ -1,53 +0,0 @@
1
- require 'test_helper'
2
-
3
- class HooksTest < MiniTest::Spec
4
- describe "Hooks.define_hook" do
5
- subject {
6
- Class.new(Object) do
7
- extend Hooks::InheritableAttribute
8
- inheritable_attr :drinks
9
- end
10
- }
11
-
12
- it "provides a reader with empty inherited attributes, already" do
13
- assert_equal nil, subject.drinks
14
- end
15
-
16
- it "provides a reader with empty inherited attributes in a derived class" do
17
- assert_equal nil, Class.new(subject).drinks
18
- #subject.drinks = true
19
- #Class.new(subject).drinks # TODO: crashes.
20
- end
21
-
22
- it "provides an attribute copy in subclasses" do
23
- subject.drinks = []
24
- assert subject.drinks.object_id != Class.new(subject).drinks.object_id
25
- end
26
-
27
- it "provides a writer" do
28
- subject.drinks = [:cabernet]
29
- assert_equal [:cabernet], subject.drinks
30
- end
31
-
32
- it "inherits attributes" do
33
- subject.drinks = [:cabernet]
34
-
35
- subklass_a = Class.new(subject)
36
- subklass_a.drinks << :becks
37
-
38
- subklass_b = Class.new(subject)
39
-
40
- assert_equal [:cabernet], subject.drinks
41
- assert_equal [:cabernet, :becks], subklass_a.drinks
42
- assert_equal [:cabernet], subklass_b.drinks
43
- end
44
-
45
- it "does not inherit attributes if we set explicitely" do
46
- subject.drinks = [:cabernet]
47
- subklass = Class.new(subject)
48
-
49
- subklass.drinks = [:merlot] # we only want merlot explicitely.
50
- assert_equal [:merlot], subklass.drinks # no :cabernet, here
51
- end
52
- end
53
- end