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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b231e9ddfdb2a5004ef5aa5228c3ac8571598d91
4
- data.tar.gz: 014ace302235591326558b0ba957ed7fa857020f
3
+ metadata.gz: e991b108ddd328284fb3ce188939bf5a725482b1
4
+ data.tar.gz: 81e062bfdfc0e338fb13281be91eed674e42f4a0
5
5
  SHA512:
6
- metadata.gz: 2a0c5c29a5718cc5828faa369b16a91ae3f877669e866cd7d1582b59cc899d18b0df4e174bc4adef027d988ebc987e8eead4b45dd676e6575900ff0d8c4ac83c
7
- data.tar.gz: 03e71ae12c31d1cf8430f5b91932fee27f4a75a4777084e87c67ae4151d19d5a2bd7921e897d3a2870f9c6efc408abd74e6504de6daf420d144a2645b7df6eb0
6
+ metadata.gz: 11f0ed8fb7a82d60d7c4768ab67bbf9e96f44573f144d9a80973aeeb8a7901f5b6dd5c19f4ed0d740f6de43e05f0e8a7c0755983c4196384c34938d6f73c5c44
7
+ data.tar.gz: ba9b6f33b50018731847f2100165e1d4678ea015552777aefdf8d6965935ab5fec73f25e503e35300ef90a7f73ab53eaa6910cd5706b71ce1e2a18974d3ab0ca
data/.travis.yml CHANGED
@@ -1,4 +1,10 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.7
3
6
  - 2.2.3
4
7
  before_install: gem install bundler -v 1.10.6
8
+ install: bundle install -j 4 --retry 3
9
+ script:
10
+ - bin/rspec
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # SimpleAspect
2
2
 
3
+ [![Build Status](https://travis-ci.org/ricardotealdi/simple_aspect.svg?branch=master)](https://travis-ci.org/ricardotealdi/simple_aspect)
4
+
3
5
  Simple AOP implementation for Ruby
4
6
 
5
7
  ## Installation
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')
@@ -1,3 +1,3 @@
1
1
  module SimpleAspect
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
data/lib/simple_aspect.rb CHANGED
@@ -1,54 +1,105 @@
1
- require "simple_aspect/version"
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
- @_sa_watcher_aspects = {}
9
- @_sa_ignoring_methods = false
10
- @_sa_lock = Mutex.new
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, instance_around_method = instance_around_method_name(method), &block
15
+ method,
16
+ instance_around_method_name = sa_instance_around_method_name(method),
17
+ &block
16
18
  )
17
- @_sa_watcher_aspects[method] = instance_around_method
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
- aspect = @_sa_watcher_aspects[method]
23
+ return if sa_should_not_redefine?(method)
27
24
 
28
- return if @_sa_ignoring_methods || !aspect
25
+ sa_redefine_original_method(method, sa_get_aspect_method_name(method))
26
+ end
29
27
 
30
- @_sa_lock.synchronize do
31
- begin
32
- @_sa_ignoring_methods = true
28
+ private
33
29
 
34
- orig_impl = instance_method(method)
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
- define_method(method) do |*args, &block|
37
- result = nil
33
+ sa_define_aspect_method(aspect_method_name, &block) if block
34
+ end
38
35
 
39
- send(aspect, *args) do
40
- result = orig_impl.bind(self).call(*args, &block)
41
- end
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
- result
44
- end
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
- @_sa_ignoring_methods = false
69
+ sa_ignore_new_methods(_ignore = false)
47
70
  end
48
71
  end
49
72
  end
50
73
 
51
- def instance_around_method_name(method)
52
- "_sa_around_#{method}".to_sym
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
@@ -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 = "simple_aspect"
7
+ spec.name = 'simple_aspect'
8
8
  spec.version = SimpleAspect::VERSION
9
- spec.authors = ["Ricardo Tealdi"]
10
- spec.email = ["ricardo.tealdi@gmail.com"]
9
+ spec.authors = ['Ricardo Tealdi']
10
+ spec.email = ['ricardo.tealdi@gmail.com']
11
11
 
12
- spec.summary = %q{Simple AOP implementation for Ruby}
13
- spec.description = %q{Simple AOP implementation for Ruby}
14
- spec.homepage = "https://github.com/ricardotealdi/simple_aspect"
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`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
- spec.bindir = "exe"
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 = ["lib"]
22
+ spec.require_paths = ['lib']
20
23
 
21
- spec.add_development_dependency "rspec"
22
- spec.add_development_dependency "pry"
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.1.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-05 00:00:00.000000000 Z
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: '0'
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: '0'
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.8
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: