hooks 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.textile CHANGED
@@ -1,3 +1,6 @@
1
+ h2. 0.2.1
2
+ * You can now pass multiple hook names to @#define_hooks@.
3
+
1
4
  h2. 0.2.0
2
5
 
3
6
  h3. Changes
data/README.rdoc CHANGED
@@ -20,10 +20,12 @@ Let's take... a cat.
20
20
  class Cat
21
21
  include Hooks
22
22
 
23
- define_hook :after_dinner
23
+ define_hooks :before_dinner, :after_dinner
24
24
 
25
25
  Now you can add callbacks to your hook declaratively in your class.
26
26
 
27
+ before_dinner :wash_paws
28
+
27
29
  after_dinner do
28
30
  puts "Ice cream for #{self}!"
29
31
  end
data/lib/hooks.rb CHANGED
@@ -5,18 +5,19 @@ require "hooks/inheritable_attribute"
5
5
  # Example:
6
6
  #
7
7
  # class CatWidget < Apotomo::Widget
8
- # define_hook :after_dinner
8
+ # define_hooks :before_dinner, :after_dinner
9
9
  #
10
10
  # Now you can add callbacks to your hook declaratively in your class.
11
11
  #
12
- # after_dinner do puts "Ice cream!" end
12
+ # before_dinner :wash_paws
13
+ # after_dinner { puts "Ice cream!" }
13
14
  # after_dinner :have_a_desert # => refers to CatWidget#have_a_desert
14
15
  #
15
16
  # Running the callbacks happens on instances. It will run the block and #have_a_desert from above.
16
17
  #
17
18
  # cat.run_hook :after_dinner
18
19
  module Hooks
19
- VERSION = "0.2.0"
20
+ VERSION = "0.2.1"
20
21
 
21
22
  def self.included(base)
22
23
  base.extend InheritableAttribute
@@ -24,12 +25,12 @@ module Hooks
24
25
  end
25
26
 
26
27
  module ClassMethods
27
- def define_hook(name)
28
- accessor_name = "_#{name}_callbacks"
29
-
30
- setup_hook_accessors(accessor_name)
31
- define_hook_writer(name, accessor_name)
28
+ def define_hooks(*names)
29
+ names.each do |name|
30
+ setup_hook(name)
31
+ end
32
32
  end
33
+ alias_method :define_hook, :define_hooks
33
34
 
34
35
  # Like Hooks#run_hook but for the class. Note that +:callbacks+ must be class methods.
35
36
  #
@@ -71,6 +72,13 @@ module Hooks
71
72
  end
72
73
 
73
74
  private
75
+
76
+ def setup_hook(name)
77
+ accessor_name = "_#{name}_callbacks"
78
+
79
+ setup_hook_accessors(accessor_name)
80
+ define_hook_writer(name, accessor_name)
81
+ end
74
82
 
75
83
  def define_hook_writer(hook, accessor_name)
76
84
  instance_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
data/test/hooks_test.rb CHANGED
@@ -29,6 +29,12 @@ class HooksTest < Test::Unit::TestCase
29
29
  @klass.after_eight :dine
30
30
  assert_equal [:dine], @klass.callbacks_for_hook(:after_eight)
31
31
  end
32
+
33
+ should "accept multiple hook names" do
34
+ @mum.class.define_hooks :before_ten, :after_ten
35
+ assert_equal [], @klass.callbacks_for_hook(:before_ten)
36
+ assert_equal [], @klass.callbacks_for_hook(:after_ten)
37
+ end
32
38
 
33
39
  context "creates a public writer for the hook that" do
34
40
  should "accepts method names" do
metadata CHANGED
@@ -1,58 +1,56 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: hooks
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 2
8
- - 0
9
- version: 0.2.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Nick Sutterer
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2011-10-06 00:00:00 +02:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-08-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: shoulda
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
31
22
  type: :development
32
- version_requirements: *id001
33
- - !ruby/object:Gem::Dependency
34
- name: rake
35
23
  prerelease: false
36
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
37
33
  none: false
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- segments:
42
- - 0
43
- version: "0"
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
44
38
  type: :development
45
- version_requirements: *id002
46
- description: Declaratively define hooks, add callbacks and run them with the options you like.
47
- email:
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Declaratively define hooks, add callbacks and run them with the options
47
+ you like.
48
+ email:
48
49
  - apotonick@gmail.com
49
50
  executables: []
50
-
51
51
  extensions: []
52
-
53
52
  extra_rdoc_files: []
54
-
55
- files:
53
+ files:
56
54
  - CHANGES.textile
57
55
  - Gemfile
58
56
  - README.rdoc
@@ -63,37 +61,31 @@ files:
63
61
  - test/hooks_test.rb
64
62
  - test/inheritable_attribute_test.rb
65
63
  - test/test_helper.rb
66
- has_rdoc: true
67
64
  homepage: http://nicksda.apotomo.de/tag/hooks
68
65
  licenses: []
69
-
70
66
  post_install_message:
71
67
  rdoc_options: []
72
-
73
- require_paths:
68
+ require_paths:
74
69
  - lib
75
- required_ruby_version: !ruby/object:Gem::Requirement
70
+ required_ruby_version: !ruby/object:Gem::Requirement
76
71
  none: false
77
- requirements:
78
- - - ">="
79
- - !ruby/object:Gem::Version
80
- segments:
81
- - 0
82
- version: "0"
83
- required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
77
  none: false
85
- requirements:
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- segments:
89
- - 0
90
- version: "0"
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
91
82
  requirements: []
92
-
93
83
  rubyforge_project:
94
- rubygems_version: 1.3.7
84
+ rubygems_version: 1.8.24
95
85
  signing_key:
96
86
  specification_version: 3
97
87
  summary: Generic hooks with callbacks for Ruby.
98
- test_files: []
99
-
88
+ test_files:
89
+ - test/hooks_test.rb
90
+ - test/inheritable_attribute_test.rb
91
+ - test/test_helper.rb