aspect4r 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.document +5 -0
  2. data/.gitignore +22 -0
  3. data/LICENSE +20 -0
  4. data/NOTES.rdoc +42 -0
  5. data/README.rdoc +70 -0
  6. data/Rakefile +45 -0
  7. data/VERSION +1 -0
  8. data/aspect4r.gemspec +108 -0
  9. data/examples/after_example.rb +30 -0
  10. data/examples/around_example.rb +29 -0
  11. data/examples/before_example.rb +62 -0
  12. data/examples/combined_example.rb +39 -0
  13. data/lib/aspect4r/after.rb +29 -0
  14. data/lib/aspect4r/around.rb +29 -0
  15. data/lib/aspect4r/base.rb +32 -0
  16. data/lib/aspect4r/before.rb +37 -0
  17. data/lib/aspect4r/classic.rb +12 -0
  18. data/lib/aspect4r/errors.rb +5 -0
  19. data/lib/aspect4r/extensions/class_extension.rb +20 -0
  20. data/lib/aspect4r/extensions/module_extension.rb +30 -0
  21. data/lib/aspect4r/helper.rb +171 -0
  22. data/lib/aspect4r/model/advice.rb +29 -0
  23. data/lib/aspect4r/model/advice_metadata.rb +27 -0
  24. data/lib/aspect4r/model/advices_for_method.rb +45 -0
  25. data/lib/aspect4r/model/aspect_data.rb +19 -0
  26. data/lib/aspect4r/return_this.rb +9 -0
  27. data/lib/aspect4r.rb +10 -0
  28. data/spec/aspect4r/after_spec.rb +121 -0
  29. data/spec/aspect4r/around_spec.rb +128 -0
  30. data/spec/aspect4r/before_spec.rb +148 -0
  31. data/spec/aspect4r/class_inheritance_spec.rb +254 -0
  32. data/spec/aspect4r/classic_spec.rb +44 -0
  33. data/spec/aspect4r/helper_spec.rb +117 -0
  34. data/spec/aspect4r/inheritance_inclusion_combined_spec.rb +98 -0
  35. data/spec/aspect4r/module_inclusion_spec.rb +208 -0
  36. data/spec/aspect4r/super_in_method_spec.rb +118 -0
  37. data/spec/aspect4r_spec.rb +295 -0
  38. data/spec/spec.opts +1 -0
  39. data/spec/spec_helper.rb +11 -0
  40. data/test/after_test.rb +30 -0
  41. data/test/around_test.rb +28 -0
  42. data/test/before_test.rb +28 -0
  43. data/test/combined_test.rb +40 -0
  44. data/test/method_invocation_test.rb +28 -0
  45. data/test/test_helper.rb +9 -0
  46. metadata +147 -0
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+ test/output
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Guoliang Cao
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/NOTES.rdoc ADDED
@@ -0,0 +1,42 @@
1
+ == TEST TODO
2
+
3
+ Class inheritance
4
+
5
+ Module inclusion
6
+
7
+ Mix aspects in body and in module
8
+
9
+ Mix aspects from multiple modules
10
+
11
+ Mix aspects in body and inherited
12
+
13
+ Mix aspects in body, inherited and in module
14
+
15
+ == optimization idea
16
+
17
+ On create method, define method as a place holder which will generate the real method on first execution
18
+
19
+ == Inheritance / inclusion
20
+
21
+ Automatically group aspects by the class/module that creates them
22
+ Before aspects defined in base class run immediately before wrapped method
23
+ After aspects run immediagely after
24
+ Around aspects wrap around wrapped method
25
+
26
+ Before aspects defined in module that are included at the beginning run before aspects from base class and after those in current class
27
+ After aspects in module run after aspects from base class and before those in current class
28
+ Around aspects in module wrap around wrapped method + before/after aspects in base class
29
+
30
+ Before aspects defined in module that are included later run before all aspects already defined so far
31
+ After aspects in module run after all aspects
32
+ Around aspects in module wrap around wrapped method + before/after aspects
33
+
34
+ == Clean up
35
+
36
+ Reduce duplication in before/after/around.rb
37
+
38
+ Include Aspect4r::Base in target module/class when a module with advices is included.
39
+
40
+ Add included_with_a4r(for module) and inherited_with_a4r(for class) when Aspect4r::Base is included
41
+
42
+ Rename class AspectForMethod, Definition etc.
data/README.rdoc ADDED
@@ -0,0 +1,70 @@
1
+ = aspect4r
2
+
3
+ Aspect Oriented Programming support for Ruby
4
+
5
+ == Feature
6
+
7
+ * extract common logic from multiple methods into before, after, around advices
8
+ * before_filter as method filters (work like before_filters in web application)
9
+ * advices can be customized (e.g. to take an optional method name argument)
10
+ * work as a supporting piece for more complex AOP tasks
11
+
12
+ == Usage
13
+
14
+ class A
15
+ include Aspect4r
16
+
17
+ around :test do |proxy_method, value|
18
+ a4r_invoke proxy_method, value
19
+ end
20
+
21
+ before :test do |value|
22
+ puts "entering test(#{value})"
23
+ end
24
+
25
+ before :test, :do_something
26
+
27
+ before_filter :test do |value|
28
+ value >= 0
29
+ end
30
+
31
+ after :test do |result, value|
32
+ puts "test(#{value}) returned #{result}"
33
+ result
34
+ end
35
+
36
+ after :test, :do_something_else
37
+
38
+ def test value
39
+ ...
40
+ end
41
+
42
+ def do_something value
43
+ ...
44
+ end
45
+
46
+ def do_something_else result, value
47
+ ...
48
+ end
49
+
50
+ end
51
+
52
+ == How does it work?
53
+
54
+ == TODO
55
+
56
+ See github issues tab http://github.com/gcao/aspect4r/issues
57
+
58
+ == Note on Patches/Pull Requests
59
+
60
+ * Fork the project.
61
+ * Make your feature addition or bug fix.
62
+ * Add tests for it. This is important so I don't break it in a
63
+ future version unintentionally.
64
+ * Commit, do not mess with rakefile, version, or history.
65
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
66
+ * Send me a pull request. Bonus points for topic branches.
67
+
68
+ == Copyright
69
+
70
+ Copyright (c) 2010 Guoliang Cao. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "aspect4r"
8
+ gem.summary = %Q{Aspect Oriented Programming for ruby}
9
+ gem.description = %Q{AOP for ruby - use before_method, after_method and around_method to trim your fat methods and reduce code duplication}
10
+ gem.email = "gcao99@gmail.com"
11
+ gem.homepage = "http://github.com/gcao/aspect4r"
12
+ gem.authors = ["Guoliang Cao"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'spec/rake/spectask'
22
+ Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.spec_files = FileList['spec/**/*_spec.rb']
25
+ end
26
+
27
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
+ spec.rcov = true
31
+ end
32
+
33
+ task :spec => :check_dependencies
34
+
35
+ task :default => :spec
36
+
37
+ require 'rake/rdoctask'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "aspect4r #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.7.1
data/aspect4r.gemspec ADDED
@@ -0,0 +1,108 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{aspect4r}
8
+ s.version = "0.7.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Guoliang Cao"]
12
+ s.date = %q{2010-06-08}
13
+ s.description = %q{AOP for ruby - use before_method, after_method and around_method to trim your fat methods and reduce code duplication}
14
+ s.email = %q{gcao99@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "NOTES.rdoc",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "aspect4r.gemspec",
28
+ "examples/after_example.rb",
29
+ "examples/around_example.rb",
30
+ "examples/before_example.rb",
31
+ "examples/combined_example.rb",
32
+ "lib/aspect4r.rb",
33
+ "lib/aspect4r/after.rb",
34
+ "lib/aspect4r/around.rb",
35
+ "lib/aspect4r/base.rb",
36
+ "lib/aspect4r/before.rb",
37
+ "lib/aspect4r/classic.rb",
38
+ "lib/aspect4r/errors.rb",
39
+ "lib/aspect4r/extensions/class_extension.rb",
40
+ "lib/aspect4r/extensions/module_extension.rb",
41
+ "lib/aspect4r/helper.rb",
42
+ "lib/aspect4r/model/advice.rb",
43
+ "lib/aspect4r/model/advice_metadata.rb",
44
+ "lib/aspect4r/model/advices_for_method.rb",
45
+ "lib/aspect4r/model/aspect_data.rb",
46
+ "lib/aspect4r/return_this.rb",
47
+ "spec/aspect4r/after_spec.rb",
48
+ "spec/aspect4r/around_spec.rb",
49
+ "spec/aspect4r/before_spec.rb",
50
+ "spec/aspect4r/class_inheritance_spec.rb",
51
+ "spec/aspect4r/classic_spec.rb",
52
+ "spec/aspect4r/helper_spec.rb",
53
+ "spec/aspect4r/inheritance_inclusion_combined_spec.rb",
54
+ "spec/aspect4r/module_inclusion_spec.rb",
55
+ "spec/aspect4r/super_in_method_spec.rb",
56
+ "spec/aspect4r_spec.rb",
57
+ "spec/spec.opts",
58
+ "spec/spec_helper.rb",
59
+ "test/after_test.rb",
60
+ "test/around_test.rb",
61
+ "test/before_test.rb",
62
+ "test/combined_test.rb",
63
+ "test/method_invocation_test.rb",
64
+ "test/test_helper.rb"
65
+ ]
66
+ s.homepage = %q{http://github.com/gcao/aspect4r}
67
+ s.rdoc_options = ["--charset=UTF-8"]
68
+ s.require_paths = ["lib"]
69
+ s.rubygems_version = %q{1.3.7}
70
+ s.summary = %q{Aspect Oriented Programming for ruby}
71
+ s.test_files = [
72
+ "spec/aspect4r/after_spec.rb",
73
+ "spec/aspect4r/around_spec.rb",
74
+ "spec/aspect4r/before_spec.rb",
75
+ "spec/aspect4r/class_inheritance_spec.rb",
76
+ "spec/aspect4r/classic_spec.rb",
77
+ "spec/aspect4r/helper_spec.rb",
78
+ "spec/aspect4r/inheritance_inclusion_combined_spec.rb",
79
+ "spec/aspect4r/module_inclusion_spec.rb",
80
+ "spec/aspect4r/super_in_method_spec.rb",
81
+ "spec/aspect4r_spec.rb",
82
+ "spec/spec_helper.rb",
83
+ "test/after_test.rb",
84
+ "test/around_test.rb",
85
+ "test/before_test.rb",
86
+ "test/combined_test.rb",
87
+ "test/method_invocation_test.rb",
88
+ "test/test_helper.rb",
89
+ "examples/after_example.rb",
90
+ "examples/around_example.rb",
91
+ "examples/before_example.rb",
92
+ "examples/combined_example.rb"
93
+ ]
94
+
95
+ if s.respond_to? :specification_version then
96
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
97
+ s.specification_version = 3
98
+
99
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
100
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
101
+ else
102
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
103
+ end
104
+ else
105
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
106
+ end
107
+ end
108
+
@@ -0,0 +1,30 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+
3
+ require 'aspect4r'
4
+
5
+ class A
6
+ include Aspect4r
7
+
8
+ def test value
9
+ puts 'test'
10
+ value
11
+ end
12
+
13
+ after :test, :result_arg => false do |value|
14
+ puts 'after test'
15
+ end
16
+
17
+ after :test do |result, value|
18
+ puts 'after test 2'
19
+ result * 100
20
+ end
21
+ end
22
+
23
+ puts "Example 1:"
24
+ puts A.new.test(1)
25
+ # ==== Output ====
26
+ # test
27
+ # after test
28
+ # after test 2
29
+ # 100
30
+
@@ -0,0 +1,29 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+
3
+ require 'aspect4r'
4
+
5
+ class A
6
+ include Aspect4r
7
+
8
+ def test value
9
+ puts 'test'
10
+ value
11
+ end
12
+
13
+ around :test do |proxy, value|
14
+ puts 'before test'
15
+ result = send proxy, value
16
+ puts 'after test'
17
+ result
18
+ end
19
+ end
20
+
21
+ puts "Example 1:"
22
+ puts A.new.test(1)
23
+ # ==== Output ====
24
+ # Example 1:
25
+ # before test
26
+ # test
27
+ # after test
28
+ # 1
29
+
@@ -0,0 +1,62 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+
3
+ require 'aspect4r'
4
+
5
+ class A
6
+ include Aspect4r
7
+
8
+ def test value
9
+ puts 'test'
10
+ end
11
+
12
+ before :test do |value|
13
+ puts 'before test'
14
+ end
15
+
16
+ before_filter :test do |value|
17
+ puts 'check before test'
18
+ value >= 0
19
+ end
20
+ end
21
+
22
+ puts "Example 1:"
23
+ A.new.test 1
24
+ # ==== Output ====
25
+ # before test
26
+ # check before test
27
+ # test
28
+
29
+ puts "\nExample 2:"
30
+ A.new.test -1
31
+ # ==== Output ====
32
+ # before test
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
@@ -0,0 +1,39 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+
3
+ require 'aspect4r'
4
+
5
+ class A
6
+ include Aspect4r
7
+
8
+ def test value
9
+ puts 'test'
10
+ value
11
+ end
12
+
13
+ around :test do |proxy, value|
14
+ puts 'around test 1'
15
+ result = a4r_invoke proxy, value
16
+ puts 'around test 2'
17
+ result
18
+ end
19
+
20
+ before :test do |value|
21
+ puts 'before test'
22
+ end
23
+
24
+ after :test do |result, value|
25
+ puts 'after test'
26
+ result
27
+ end
28
+ end
29
+
30
+ puts "Example 1:"
31
+ puts A.new.test(1)
32
+ # ==== Output ====
33
+ # Example 1:
34
+ # before test
35
+ # around test 1
36
+ # test
37
+ # around test 2
38
+ # after test
39
+ # 1
@@ -0,0 +1,29 @@
1
+ require 'aspect4r/base'
2
+
3
+ module Aspect4r
4
+ module After
5
+ def self.included(base)
6
+ base.send(:include, Base::InstanceMethods)
7
+ base.extend(Base::ClassMethods, ClassMethods)
8
+ end
9
+
10
+ module ClassMethods
11
+ def after *methods, &block
12
+ Aspect4r::Helper.process_advice Aspect4r::Model::AdviceMetadata::AFTER, self, methods, &block
13
+ end
14
+ end
15
+
16
+ module Classic
17
+ def self.included(base)
18
+ base.send(:include, Base::InstanceMethods)
19
+ base.extend(Base::ClassMethods, ClassMethods)
20
+ end
21
+
22
+ module ClassMethods
23
+ def a4r_after *methods, &block
24
+ Aspect4r::Helper.process_advice Aspect4r::Model::AdviceMetadata::AFTER, self, methods, &block
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ require 'aspect4r/base'
2
+
3
+ module Aspect4r
4
+ module Around
5
+ def self.included(base)
6
+ base.send(:include, Base::InstanceMethods)
7
+ base.extend(Base::ClassMethods, ClassMethods)
8
+ end
9
+
10
+ module ClassMethods
11
+ def around *methods, &block
12
+ Aspect4r::Helper.process_advice Aspect4r::Model::AdviceMetadata::AROUND, self, methods, &block
13
+ end
14
+ end
15
+
16
+ module Classic
17
+ def self.included(base)
18
+ base.send(:include, Base::InstanceMethods)
19
+ base.extend(Base::ClassMethods, ClassMethods)
20
+ end
21
+
22
+ module ClassMethods
23
+ def a4r_around *methods, &block
24
+ Aspect4r::Helper.process_advice Aspect4r::Model::AdviceMetadata::AROUND, self, methods, &block
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,32 @@
1
+ require 'aspect4r/errors'
2
+ require 'aspect4r/model/advice'
3
+ require 'aspect4r/model/advices_for_method'
4
+ require 'aspect4r/model/aspect_data'
5
+ require 'aspect4r/model/advice_metadata'
6
+ require 'aspect4r/return_this'
7
+
8
+ require 'aspect4r/helper'
9
+
10
+ require 'aspect4r/extensions/class_extension'
11
+ require 'aspect4r/extensions/module_extension'
12
+
13
+ module Aspect4r
14
+ module Base
15
+ def self.included(base)
16
+ base.send(:include, InstanceMethods)
17
+ base.extend(ClassMethods)
18
+ end
19
+
20
+ module InstanceMethods
21
+ def a4r_invoke proxy, *args
22
+ proxy.bind(self).call *args
23
+ end
24
+ end
25
+
26
+ module ClassMethods
27
+ def a4r_data
28
+ @a4r_data ||= Aspect4r::Model::AspectData.new
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,37 @@
1
+ require 'aspect4r/base'
2
+
3
+ module Aspect4r
4
+ module Before
5
+ def self.included(base)
6
+ base.send(:include, Base::InstanceMethods)
7
+ base.extend(Base::ClassMethods, ClassMethods)
8
+ end
9
+
10
+ module ClassMethods
11
+ def before *methods, &block
12
+ Aspect4r::Helper.process_advice Aspect4r::Model::AdviceMetadata::BEFORE, self, methods, &block
13
+ end
14
+
15
+ def before_filter *methods, &block
16
+ Aspect4r::Helper.process_advice Aspect4r::Model::AdviceMetadata::BEFORE_FILTER, self, methods, &block
17
+ end
18
+ end
19
+
20
+ module Classic
21
+ def self.included(base)
22
+ base.send(:include, Base::InstanceMethods)
23
+ base.extend(Base::ClassMethods, ClassMethods)
24
+ end
25
+
26
+ module ClassMethods
27
+ def a4r_before *methods, &block
28
+ Aspect4r::Helper.process_advice Aspect4r::Model::AdviceMetadata::BEFORE, self, methods, &block
29
+ end
30
+
31
+ def a4r_before_filter *methods, &block
32
+ Aspect4r::Helper.process_advice Aspect4r::Model::AdviceMetadata::BEFORE_FILTER, self, methods, &block
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,12 @@
1
+ require 'aspect4r/before'
2
+ require 'aspect4r/after'
3
+ require 'aspect4r/around'
4
+
5
+ module Aspect4r
6
+ module Classic
7
+ def self.included(base)
8
+ base.send(:include, Base::InstanceMethods)
9
+ base.extend Base::ClassMethods, Before::Classic::ClassMethods, After::Classic::ClassMethods, Around::Classic::ClassMethods
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module Aspect4r
2
+ class Error < StandardError
3
+
4
+ end
5
+ end
@@ -0,0 +1,20 @@
1
+ class Class
2
+ def inherited_with_a4r(child)
3
+ inherited_without_a4r(child) if respond_to?(:inherited_without_a4r, true)
4
+
5
+ return if @a4r_data.nil? or @a4r_data.empty?
6
+
7
+ a4r_data = Aspect4r::Model::AspectData.new
8
+
9
+ # @a4r_data.each do |key, value|
10
+ # a4r_data[key] = (value.clone rescue value)
11
+ # end
12
+
13
+ a4r_data.methods_with_advices.merge(@a4r_data.methods_with_advices)
14
+
15
+ child.instance_variable_set('@a4r_data', a4r_data)
16
+ end
17
+
18
+ alias inherited_without_a4r inherited
19
+ alias inherited inherited_with_a4r
20
+ end
@@ -0,0 +1,30 @@
1
+ class Module
2
+ def included_with_a4r(base)
3
+ included_without_a4r(child) if respond_to?(:included_without_a4r)
4
+
5
+ return if @a4r_data.nil? or @a4r_data.empty?
6
+
7
+ base.send(:include, Aspect4r)
8
+
9
+ existing_aspects = base.a4r_data
10
+ existing_aspects.methods_with_advices.merge(@a4r_data.methods_with_advices)
11
+ end
12
+
13
+ alias included_without_a4r included
14
+ alias included included_with_a4r
15
+
16
+ def method_added_with_a4r(method)
17
+ method_added_without_a4r(child) if respond_to?(:method_added_without_a4r)
18
+
19
+ return if method.to_s =~ /a4r/
20
+
21
+ # save unbound method and create new method
22
+ if not Aspect4r::Helper.creating_method? and @a4r_data and method_advices = @a4r_data[method]
23
+ method_advices.wrapped_method = instance_method(method)
24
+ Aspect4r::Helper.create_method self, method
25
+ end
26
+ end
27
+
28
+ alias method_added_without_a4r method_added
29
+ alias method_added method_added_with_a4r
30
+ end