aspector 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/Gemfile +2 -2
  2. data/Gemfile.lock +6 -9
  3. data/README.rdoc +5 -4
  4. data/VERSION +1 -1
  5. data/aspector.gemspec +29 -20
  6. data/examples/activerecord_hooks.rb +2 -2
  7. data/examples/around_example.rb +1 -0
  8. data/examples/aspector_apply_example.rb +4 -3
  9. data/examples/aspector_example.rb +1 -0
  10. data/examples/cache_aspect.rb +2 -2
  11. data/examples/exception_handler.rb +36 -0
  12. data/examples/logging_aspect.rb +35 -0
  13. data/examples/retry_aspect.rb +41 -0
  14. data/lib/aspector/advice.rb +3 -7
  15. data/lib/aspector/base.rb +52 -29
  16. data/lib/aspector/context.rb +2 -1
  17. data/lib/aspector/deferred_logic.rb +3 -7
  18. data/lib/aspector/method_matcher.rb +6 -9
  19. data/performance-tests/after_test.rb +25 -0
  20. data/performance-tests/around_test.rb +27 -0
  21. data/performance-tests/before_test.rb +25 -0
  22. data/performance-tests/combined_test.rb +33 -0
  23. data/performance-tests/method_invocation_test.rb +25 -0
  24. data/performance-tests/test_helper.rb +9 -0
  25. data/spec/functional/advices_on_private_methods_spec.rb +21 -0
  26. data/spec/functional/aspect_on_eigen_class_spec.rb +66 -0
  27. data/spec/functional/aspect_on_object_spec.rb +20 -0
  28. data/spec/{aspector_spec.rb → functional/aspector_spec.rb} +13 -57
  29. data/spec/functional/aspects_combined_spec.rb +42 -0
  30. data/spec/functional/execution_order_spec.rb +36 -0
  31. data/spec/spec_helper.rb +16 -1
  32. data/spec/unit/advice_spec.rb +4 -0
  33. data/spec/{aspector → unit}/after_spec.rb +42 -38
  34. data/spec/{aspector → unit}/around_spec.rb +22 -18
  35. data/spec/unit/base_class_methods_spec.rb +28 -0
  36. data/spec/unit/base_spec.rb +81 -0
  37. data/spec/{aspector → unit}/before_spec.rb +27 -18
  38. data/spec/unit/deferred_logic_spec.rb +23 -0
  39. data/spec/unit/method_matcher_spec.rb +43 -0
  40. metadata +63 -69
  41. data/spec/advices_on_private_methods_spec.rb +0 -29
  42. data/spec/aspect_on_eigen_class_spec.rb +0 -86
  43. data/spec/aspect_on_object_spec.rb +0 -32
  44. data/spec/aspector/aspect_spec.rb +0 -86
  45. data/spec/aspector/base_spec.rb +0 -35
  46. data/spec/aspects_combined_spec.rb +0 -55
  47. data/spec/execution_order_spec.rb +0 -62
@@ -1,86 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe "Miscellaneous" do
4
- it "#apply" do
5
- klass = Class.new do
6
- def value
7
- @value ||= []
8
- end
9
-
10
- def test
11
- value << "test"
12
- end
13
-
14
- def do_this
15
- value << "do_this"
16
- end
17
- end
18
-
19
- aspect = Aspector do
20
- before :test, :do_this
21
- end
22
-
23
- aspect.apply(klass)
24
-
25
- obj = klass.new
26
- obj.test
27
- obj.value.should == %w"do_this test"
28
- end
29
-
30
- it "can add method to target" do
31
- klass = Class.new do
32
- def value
33
- @value ||= []
34
- end
35
-
36
- def test
37
- value << "test"
38
- end
39
- end
40
-
41
- aspect = Aspector do
42
- target do
43
- def do_this
44
- value << "do_this"
45
- end
46
- end
47
-
48
- before :test, :do_this
49
- end
50
-
51
- aspect.apply(klass)
52
-
53
- obj = klass.new
54
- obj.test
55
- obj.value.should == %w"do_this test"
56
- end
57
-
58
- it "target takes String too" do
59
- klass = Class.new do
60
- def value
61
- @value ||= []
62
- end
63
-
64
- def test
65
- value << "test"
66
- end
67
- end
68
-
69
- aspect = Aspector do
70
- target '
71
- def do_this
72
- value << "do_this"
73
- end
74
- '
75
-
76
- before :test, :do_this
77
- end
78
-
79
- aspect.apply(klass)
80
-
81
- obj = klass.new
82
- obj.test
83
- obj.value.should == %w"do_this test"
84
- end
85
-
86
- end
@@ -1,35 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe "Aspector::Base" do
4
- it "Default options" do
5
- aspect = Aspector do
6
- default :test => 'value'
7
- end
8
-
9
- aspect.default_options[:test].should == 'value'
10
- end
11
-
12
- it "deferred_option" do
13
- klass = Class.new do
14
- def value
15
- @value ||= []
16
- end
17
-
18
- def test
19
- value << "test"
20
- end
21
- end
22
-
23
- aspect = Aspector do
24
- before options[:methods] do
25
- value << "do_this"
26
- end
27
- end
28
-
29
- aspect.apply(klass, :methods => [:test])
30
-
31
- obj = klass.new
32
- obj.test
33
- obj.value.should == %w"do_this test"
34
- end
35
- end
@@ -1,55 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe "Aspects combined" do
4
- it "should work" do
5
- klass = Class.new do
6
- def value
7
- @value ||= []
8
- end
9
-
10
- def test
11
- value << "test"
12
- end
13
-
14
- def do_before
15
- value << "do_before"
16
- end
17
-
18
- def do_after result
19
- value << "do_after"
20
- result
21
- end
22
-
23
- def do_around &block
24
- value << "do_around_before"
25
- result = block.call
26
- value << "do_around_after"
27
- result
28
- end
29
- end
30
-
31
- aspector(klass) do
32
- before :test, :do_before
33
- after :test, :do_after
34
- around :test, :do_around
35
- end
36
-
37
- klass.class_eval do
38
- aspector do
39
- before(:test) { value << "do_before_block" }
40
- end
41
-
42
- def self.method_added method
43
- method_added_aspector(method)
44
- end
45
-
46
- def test
47
- value << "new_test"
48
- end
49
- end
50
-
51
- obj = klass.new
52
- obj.test
53
- obj.value.should == %w"do_before_block do_before do_around_before new_test do_around_after do_after"
54
- end
55
- end
@@ -1,62 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe "Aspect execution order" do
4
- it "should work" do
5
- klass = Class.new do
6
- def value
7
- @value ||= []
8
- end
9
-
10
- def test
11
- value << "test"
12
- end
13
-
14
- def do_before1
15
- value << "do_before1"
16
- end
17
-
18
- def do_before2
19
- value << "do_before2"
20
- end
21
-
22
- def do_after1 result
23
- value << "do_after1"
24
- result
25
- end
26
-
27
- def do_after2 result
28
- value << "do_after2"
29
- result
30
- end
31
-
32
- def do_around1 &block
33
- value << "do_around_before1"
34
- result = block.call
35
- value << "do_around_after1"
36
- result
37
- end
38
-
39
- def do_around2 &block
40
- value << "do_around_before2"
41
- result = block.call
42
- value << "do_around_after2"
43
- result
44
- end
45
-
46
- end
47
-
48
- aspector(klass) do
49
- before :test, :do_before1
50
- after :test, :do_after1
51
- around :test, :do_around1
52
- before :test, :do_before2
53
- after :test, :do_after2
54
- around :test, :do_around2
55
- end
56
-
57
- obj = klass.new
58
- obj.test
59
- obj.value.should == %w"do_before1 do_before2 do_around_before1 do_around_before2 test
60
- do_around_after2 do_around_after1 do_after1 do_after2"
61
- end
62
- end