hooked 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -7,72 +7,103 @@ Getting Started
7
7
  ---------------
8
8
 
9
9
  By including `Hooked` into a class you basically say "everything can attach code
10
- to instance methods of this class".
11
-
12
- ``` ruby
13
- require "hooked"
14
-
15
- class Foo
16
- include Hooked
17
-
18
- def breakfast
19
- puts "No milk?!"
20
- end
21
- end
22
-
23
- class BetterFoo
24
- def shower
25
- puts "Oooh..."
26
- end
27
-
28
- def fuuu(inner)
29
- puts "FUUU!"
30
- inner.call
31
- puts "FUUU!"
32
- end
33
- end
34
-
35
- foo, better_foo = Foo.new, BetterFoo.new
36
- foo.before :breakfast, better_foo.method(:shower)
37
- foo.after :breakfast, proc { puts "Mmmh..." }
38
- foo.around :breakfast, better_foo.method(:fuuu)
39
-
40
- foo.breakfast
41
- ```
10
+ to methods of this class' objects".
11
+
12
+ require "hooked"
13
+
14
+ class Foo
15
+ include Hooked
16
+
17
+ def breakfast
18
+ puts "No milk?!"
19
+ end
20
+ end
21
+
22
+ class BetterFoo
23
+ def shower
24
+ puts "Oooh..."
25
+ end
26
+
27
+ def fuuu(inner)
28
+ puts "FUUU!"
29
+ inner.call
30
+ puts "FUUU!"
31
+ end
32
+ end
33
+
34
+ Foo.extend Hooked
35
+ Foo.before :new do
36
+ puts "Creating object..."
37
+ end
38
+
39
+ foo, better_foo = Foo.new, BetterFoo.new
40
+
41
+ foo.before :breakfast, better_foo.method(:shower)
42
+ foo.after :breakfast do
43
+ puts "Mmmh..."
44
+ end
45
+ foo.around :breakfast, better_foo.method(:fuuu), :before => better_foo.method(:shower)
46
+
47
+ foo.breakfast
42
48
 
43
49
  This will output:
44
50
 
45
- ```
46
- FUUU!
47
- Oooh...
48
- No milk?!
49
- Mmmh...
50
- FUUU!
51
- ```
51
+ Creating object...
52
+ Oooh...
53
+ FUUU!
54
+ No milk?!
55
+ FUUU!
56
+ Mmmh...
57
+
58
+ You can also aspectify instance methods of classes in order to avoid the need of
59
+ aspectifying the respective methods of each new object.
60
+
61
+ class Foo
62
+ include Hooked
63
+
64
+ def breakfast; end
65
+ end
66
+
67
+ Foo.instance_after :breakfast do
68
+ puts "ZOMG hooked!1"
69
+ end
70
+
71
+ Foo.new.breakfast
72
+
73
+ This will not affect objects that have been created before including Hooked.
52
74
 
53
75
  Execution Model
54
76
  ---------------
55
77
 
56
- TOOD
78
+ Hooked converts a method's aspects into a Directed Acyclic Graph, flattens it
79
+ using TSort and finally forms a Chain of Responsibility with the original method
80
+ at its end. As you can see in the below ASCII art, the aspect type (before,
81
+ after, around) doesn't determine sorting order. Instead it determines if the
82
+ aspect executes its code on the way into or out of the chain.
57
83
 
58
- Dependencies / Execution Order of Aspects
59
- -----------------------------------------
84
+ -->-| #1 before |-->-| |-->-| #3 before |-->-| |-->-| |
85
+ | | | #2 around | | | | | | original method |
86
+ -<--| |-<--| |-<--| |-<--| #4 after |-<--| |
60
87
 
61
- TODO
88
+ Before / After / Around
89
+ -----------------------
90
+
91
+ TODO
92
+
93
+ Execution Order of Aspects
94
+ --------------------------
95
+
96
+ TODO
62
97
 
63
98
  Possible Use Cases
64
99
  ------------------
65
100
 
66
101
  You can use the `Hook` class to programmatically build graphs of aspects.
67
102
 
68
- ``` ruby
69
- # code
70
- ```
103
+ TODO
71
104
 
72
- TODO
73
-
74
- Dependencies
75
- ------------
105
+ Dependencies / Compatibility
106
+ ----------------------------
76
107
 
77
108
  * stdlib's [TSort](http://rubydoc.info/stdlib/tsort/1.9.2/frames)
78
109
  * [RSpec](http://relishapp.com/rspec) for development
data/lib/hooked/aspect.rb CHANGED
@@ -26,6 +26,8 @@ module Hooked
26
26
  end
27
27
 
28
28
  advice.call result if after?
29
+
30
+ result
29
31
  end
30
32
 
31
33
  def before?
@@ -1,3 +1,3 @@
1
1
  module Hooked
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hooked
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
4
  prerelease:
6
- segments:
7
- - 0
8
- - 3
9
- - 2
10
- version: 0.3.2
5
+ version: 0.3.3
11
6
  platform: ruby
12
7
  authors:
13
8
  - Lars Gierth
@@ -15,22 +10,18 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-05-16 00:00:00 +02:00
19
- default_executable:
13
+ date: 2011-05-16 00:00:00 Z
20
14
  dependencies:
21
15
  - !ruby/object:Gem::Dependency
22
- prerelease: false
23
- type: :development
24
16
  name: rspec
25
17
  requirement: &id001 !ruby/object:Gem::Requirement
26
18
  none: false
27
19
  requirements:
28
20
  - - ">="
29
21
  - !ruby/object:Gem::Version
30
- hash: 3
31
- segments:
32
- - 0
33
22
  version: "0"
23
+ type: :development
24
+ prerelease: false
34
25
  version_requirements: *id001
35
26
  description: Hooked lets you transparently aspectify your methods and blocks.
36
27
  email:
@@ -58,7 +49,6 @@ files:
58
49
  - spec/hook_spec.rb
59
50
  - spec/hooked_spec.rb
60
51
  - spec/spec_helper.rb
61
- has_rdoc: true
62
52
  homepage: http://rubygems.org/gems/hooked
63
53
  licenses: []
64
54
 
@@ -72,7 +62,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
72
62
  requirements:
73
63
  - - ">="
74
64
  - !ruby/object:Gem::Version
75
- hash: 3
65
+ hash: 312125903
76
66
  segments:
77
67
  - 0
78
68
  version: "0"
@@ -81,14 +71,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
71
  requirements:
82
72
  - - ">="
83
73
  - !ruby/object:Gem::Version
84
- hash: 3
74
+ hash: 312125903
85
75
  segments:
86
76
  - 0
87
77
  version: "0"
88
78
  requirements: []
89
79
 
90
80
  rubyforge_project:
91
- rubygems_version: 1.5.2
81
+ rubygems_version: 1.8.2
92
82
  signing_key:
93
83
  specification_version: 3
94
84
  summary: Aspect Orientation Made Simple