aspect4r 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.0
1
+ 0.8.1
data/aspect4r.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{aspect4r}
8
- s.version = "0.8.0"
8
+ s.version = "0.8.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Guoliang Cao"]
12
- s.date = %q{2010-06-10}
12
+ s.date = %q{2010-06-11}
13
13
  s.description = %q{AOP for ruby - use before, after and around to trim your fat methods and reduce code duplication}
14
14
  s.email = %q{gcao99@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -99,7 +99,8 @@ Gem::Specification.new do |s|
99
99
  "examples/after_example.rb",
100
100
  "examples/around_example.rb",
101
101
  "examples/before_example.rb",
102
- "examples/combined_example.rb"
102
+ "examples/combined_example.rb",
103
+ "examples/method_to_advices_example.rb"
103
104
  ]
104
105
 
105
106
  if s.respond_to? :specification_version then
@@ -12,7 +12,7 @@ class A
12
12
 
13
13
  around :test do |proxy, value|
14
14
  puts 'before test'
15
- result = send proxy, value
15
+ result = a4r_invoke proxy, value
16
16
  puts 'after test'
17
17
  result
18
18
  end
@@ -31,32 +31,3 @@ A.new.test -1
31
31
  # ==== Output ====
32
32
  # before test
33
33
  # check before test
34
-
35
-
36
- module M
37
- include Aspect4r
38
-
39
- before :test do |value|
40
- puts 'before test'
41
- end
42
-
43
- before_filter :test do |value|
44
- puts 'check before test'
45
- value >= 0
46
- end
47
- end
48
-
49
- class B
50
- def test value
51
- puts 'test'
52
- end
53
-
54
- include M
55
- end
56
-
57
- puts "\nExample 3:"
58
- B.new.test 1
59
- # ==== Output ====
60
- # before test
61
- # check before test
62
- # test
File without changes
data/lib/aspect4r/base.rb CHANGED
@@ -36,6 +36,25 @@ module Aspect4r
36
36
  a4r_data.change_group
37
37
  end
38
38
  end
39
+
40
+ def a4r_disable_advices_temporarily *methods
41
+ methods.each do |method|
42
+ advices = a4r_data[method.to_sym]
43
+ next if advices.nil? or advices.empty?
44
+
45
+ Aspect4r::Helper.define_method self, method, advices.wrapped_method
46
+ end
47
+
48
+ yield
49
+ ensure
50
+ methods.each do |method|
51
+ advices = a4r_data[method.to_sym]
52
+
53
+ next if advices.nil? or advices.empty?
54
+
55
+ Aspect4r::Helper.create_method self, method
56
+ end
57
+ end
39
58
  end
40
59
  end
41
60
  end
@@ -13,6 +13,13 @@ module Aspect4r
13
13
  @creating_method
14
14
  end
15
15
 
16
+ def self.define_method klass_or_module, *args, &block
17
+ @creating_method = true
18
+ klass_or_module.send :define_method, *args, &block
19
+ ensure
20
+ @creating_method = false
21
+ end
22
+
16
23
  def self.eigen_class klass_or_module
17
24
  klass_or_module.module_eval do
18
25
  class << self
@@ -37,13 +44,15 @@ module Aspect4r
37
44
  with_method = methods.pop
38
45
  end
39
46
 
47
+ a4r_data = klass_or_module.a4r_data
48
+ advice = Aspect4r::Model::Advice.new(meta_data.advice_type, with_method, a4r_data.group, options)
49
+
40
50
  methods.each do |method|
41
51
  method = method.to_sym
42
52
  klass_or_module.a4r_data.methods_with_advices << method
43
53
 
44
- a4r_data = klass_or_module.a4r_data
45
- aspect = a4r_data[method] ||= Aspect4r::Model::AdvicesForMethod.new(method)
46
- aspect.add Aspect4r::Model::Advice.new(meta_data.advice_type, with_method, a4r_data.group, options)
54
+ aspect = a4r_data[method] ||= Aspect4r::Model::AdvicesForMethod.new(method)
55
+ aspect.add advice
47
56
 
48
57
  if not aspect.wrapped_method and klass_or_module.instance_methods.include?(method.to_s)
49
58
  aspect.wrapped_method = klass_or_module.instance_method(method)
@@ -58,12 +67,8 @@ module Aspect4r
58
67
  @creating_method = true
59
68
 
60
69
  aspect = klass.a4r_data[method.to_sym]
61
-
62
- if aspect.nil? or aspect.empty?
63
- # There is no aspect defined.
64
- @creating_method = nil
65
- return
66
- end
70
+
71
+ return if aspect.nil? or aspect.empty?
67
72
 
68
73
  grouped_advices = []
69
74
  group = nil
@@ -93,7 +98,7 @@ module Aspect4r
93
98
  unless grouped_advices.empty?
94
99
  create_method_for_before_after_advices klass, method, grouped_advices, inner_most unless grouped_advices.empty?
95
100
  end
96
-
101
+ ensure
97
102
  @creating_method = nil
98
103
  end
99
104
 
@@ -99,4 +99,13 @@ describe "Test Advices" do
99
99
 
100
100
  o.value.should == %w(after)
101
101
  end
102
+
103
+ it "test method without advices" do
104
+ @klass.a4r_disable_advices_temporarily :test do
105
+ o = @klass.new
106
+ o.test 1
107
+
108
+ o.value.should == %w(test)
109
+ end
110
+ end
102
111
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aspect4r
3
3
  version: !ruby/object:Gem::Version
4
- hash: 63
4
+ hash: 61
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 0
10
- version: 0.8.0
9
+ - 1
10
+ version: 0.8.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Guoliang Cao
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-10 00:00:00 -04:00
18
+ date: 2010-06-11 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -94,6 +94,7 @@ files:
94
94
  - test/combined_test.rb
95
95
  - test/method_invocation_test.rb
96
96
  - test/test_helper.rb
97
+ - examples/method_to_advices_example.rb
97
98
  has_rdoc: true
98
99
  homepage: http://github.com/gcao/aspect4r
99
100
  licenses: []
@@ -155,3 +156,4 @@ test_files:
155
156
  - examples/around_example.rb
156
157
  - examples/before_example.rb
157
158
  - examples/combined_example.rb
159
+ - examples/method_to_advices_example.rb