simple_aspect 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +6 -0
- data/README.md +2 -0
- data/bin/rspec +16 -0
- data/lib/simple_aspect/version.rb +1 -1
- data/lib/simple_aspect.rb +78 -27
- data/simple_aspect.gemspec +14 -11
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e991b108ddd328284fb3ce188939bf5a725482b1
|
4
|
+
data.tar.gz: 81e062bfdfc0e338fb13281be91eed674e42f4a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11f0ed8fb7a82d60d7c4768ab67bbf9e96f44573f144d9a80973aeeb8a7901f5b6dd5c19f4ed0d740f6de43e05f0e8a7c0755983c4196384c34938d6f73c5c44
|
7
|
+
data.tar.gz: ba9b6f33b50018731847f2100165e1d4678ea015552777aefdf8d6965935ab5fec73f25e503e35300ef90a7f73ab53eaa6910cd5706b71ce1e2a18974d3ab0ca
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
data/bin/rspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'rspec' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('rspec-core', 'rspec')
|
data/lib/simple_aspect.rb
CHANGED
@@ -1,54 +1,105 @@
|
|
1
|
-
require
|
1
|
+
require 'simple_aspect/version'
|
2
2
|
|
3
3
|
module SimpleAspect
|
4
4
|
require 'thread'
|
5
5
|
|
6
6
|
def self.extended(base)
|
7
7
|
base.instance_eval do
|
8
|
-
@
|
9
|
-
@
|
10
|
-
@
|
8
|
+
@sa_methods_to_aspect_methods_name = {}
|
9
|
+
@sa_ignoring_new_methods = false
|
10
|
+
@sa_mutex = Mutex.new
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
def aspect_around(
|
15
|
-
method,
|
15
|
+
method,
|
16
|
+
instance_around_method_name = sa_instance_around_method_name(method),
|
17
|
+
&block
|
16
18
|
)
|
17
|
-
|
18
|
-
|
19
|
-
if block
|
20
|
-
define_method(instance_around_method, &block)
|
21
|
-
self.instance_eval { private instance_around_method }
|
22
|
-
end
|
19
|
+
sa_register_aspect_on_method(method, instance_around_method_name, &block)
|
23
20
|
end
|
24
21
|
|
25
22
|
def method_added(method)
|
26
|
-
|
23
|
+
return if sa_should_not_redefine?(method)
|
27
24
|
|
28
|
-
|
25
|
+
sa_redefine_original_method(method, sa_get_aspect_method_name(method))
|
26
|
+
end
|
29
27
|
|
30
|
-
|
31
|
-
begin
|
32
|
-
@_sa_ignoring_methods = true
|
28
|
+
private
|
33
29
|
|
34
|
-
|
30
|
+
def sa_register_aspect_on_method(method, aspect_method_name, &block)
|
31
|
+
sa_set_aspect_method_name(method, aspect_method_name)
|
35
32
|
|
36
|
-
|
37
|
-
|
33
|
+
sa_define_aspect_method(aspect_method_name, &block) if block
|
34
|
+
end
|
38
35
|
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
def sa_define_aspect_method(aspect_method_name, &block)
|
37
|
+
define_method(aspect_method_name, &block)
|
38
|
+
instance_eval { private aspect_method_name }
|
39
|
+
end
|
42
40
|
|
43
|
-
|
44
|
-
|
41
|
+
def sa_redefine_original_method(method, aspect_method)
|
42
|
+
sa_avoid_infinite_recursion do
|
43
|
+
define_method(
|
44
|
+
method, &sa_aspect_method_definition(
|
45
|
+
aspect_method, instance_method(method)
|
46
|
+
)
|
47
|
+
)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def sa_aspect_method_definition(
|
52
|
+
aspect_method, unbinded_original_implementation
|
53
|
+
)
|
54
|
+
proc do |*args, &block|
|
55
|
+
result = nil
|
56
|
+
send(aspect_method, *args) do
|
57
|
+
result = unbinded_original_implementation.bind(self).call(*args, &block)
|
58
|
+
end
|
59
|
+
result
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def sa_avoid_infinite_recursion
|
64
|
+
sa_mutex.synchronize do
|
65
|
+
begin
|
66
|
+
sa_ignore_new_methods
|
67
|
+
yield
|
45
68
|
ensure
|
46
|
-
|
69
|
+
sa_ignore_new_methods(_ignore = false)
|
47
70
|
end
|
48
71
|
end
|
49
72
|
end
|
50
73
|
|
51
|
-
def
|
52
|
-
|
74
|
+
def sa_should_redefine?(method)
|
75
|
+
!sa_ignoring_new_methods? && sa_get_aspect_method_name(method)
|
76
|
+
end
|
77
|
+
|
78
|
+
def sa_should_not_redefine?(method)
|
79
|
+
!sa_should_redefine?(method)
|
80
|
+
end
|
81
|
+
|
82
|
+
def sa_get_aspect_method_name(method)
|
83
|
+
@sa_methods_to_aspect_methods_name[method]
|
84
|
+
end
|
85
|
+
|
86
|
+
def sa_set_aspect_method_name(method, instance_around_method)
|
87
|
+
@sa_methods_to_aspect_methods_name[method] = instance_around_method
|
88
|
+
end
|
89
|
+
|
90
|
+
def sa_ignoring_new_methods?
|
91
|
+
@sa_ignoring_new_methods
|
92
|
+
end
|
93
|
+
|
94
|
+
def sa_ignore_new_methods(ignore = true)
|
95
|
+
@sa_ignoring_new_methods = ignore
|
96
|
+
end
|
97
|
+
|
98
|
+
def sa_mutex
|
99
|
+
@sa_mutex
|
100
|
+
end
|
101
|
+
|
102
|
+
def sa_instance_around_method_name(method)
|
103
|
+
"sa_around_#{method}".to_sym
|
53
104
|
end
|
54
105
|
end
|
data/simple_aspect.gemspec
CHANGED
@@ -4,20 +4,23 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'simple_aspect/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'simple_aspect'
|
8
8
|
spec.version = SimpleAspect::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Ricardo Tealdi']
|
10
|
+
spec.email = ['ricardo.tealdi@gmail.com']
|
11
11
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
12
|
+
spec.summary = 'Simple AOP implementation for Ruby'
|
13
|
+
spec.description = 'Simple AOP implementation for Ruby'
|
14
|
+
spec.homepage = 'https://github.com/ricardotealdi/simple_aspect'
|
15
15
|
|
16
|
-
spec.files = `git ls-files -z
|
17
|
-
|
16
|
+
spec.files = `git ls-files -z`
|
17
|
+
.split("\x0")
|
18
|
+
.reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
|
20
|
+
spec.bindir = 'exe'
|
18
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
-
spec.require_paths = [
|
22
|
+
spec.require_paths = ['lib']
|
20
23
|
|
21
|
-
spec.add_development_dependency
|
22
|
-
spec.add_development_dependency
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.4.0'
|
25
|
+
spec.add_development_dependency 'pry'
|
23
26
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_aspect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ricardo Tealdi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 3.4.0
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 3.4.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: pry
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,6 +53,7 @@ files:
|
|
53
53
|
- README.md
|
54
54
|
- Rakefile
|
55
55
|
- bin/console
|
56
|
+
- bin/rspec
|
56
57
|
- bin/setup
|
57
58
|
- lib/simple_aspect.rb
|
58
59
|
- lib/simple_aspect/version.rb
|
@@ -76,8 +77,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
77
|
version: '0'
|
77
78
|
requirements: []
|
78
79
|
rubyforge_project:
|
79
|
-
rubygems_version: 2.4.
|
80
|
+
rubygems_version: 2.4.5.1
|
80
81
|
signing_key:
|
81
82
|
specification_version: 4
|
82
83
|
summary: Simple AOP implementation for Ruby
|
83
84
|
test_files: []
|
85
|
+
has_rdoc:
|