simple_aspect 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b231e9ddfdb2a5004ef5aa5228c3ac8571598d91
4
+ data.tar.gz: 014ace302235591326558b0ba957ed7fa857020f
5
+ SHA512:
6
+ metadata.gz: 2a0c5c29a5718cc5828faa369b16a91ae3f877669e866cd7d1582b59cc899d18b0df4e174bc4adef027d988ebc987e8eead4b45dd676e6575900ff0d8c4ac83c
7
+ data.tar.gz: 03e71ae12c31d1cf8430f5b91932fee27f4a75a4777084e87c67ae4151d19d5a2bd7921e897d3a2870f9c6efc408abd74e6504de6daf420d144a2645b7df6eb0
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in simple_aspect.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Ricardo Tealdi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # SimpleAspect
2
+
3
+ Simple AOP implementation for Ruby
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'simple_aspect'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install simple_aspect
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'simple_aspect'
25
+
26
+ class Worker
27
+ extend SimpleAspect
28
+
29
+ aspect_around :perform do |*args, &original|
30
+ puts "Before: \"args\" => #{args}"
31
+ result = original.call # Don't forget to `call` the original implementation
32
+ puts "After: \"result\" => #{result}, \"args\" => #{args}"
33
+ end
34
+
35
+ def perform(n1, n2)
36
+ puts 'doing something'
37
+ yield if block_given?
38
+ n1 + n2
39
+ end
40
+ end
41
+ ```
42
+
43
+ or
44
+
45
+ ```ruby
46
+ require 'simple_aspect'
47
+
48
+ class Worker
49
+ extend SimpleAspect
50
+
51
+ aspect_around :perform, :around_perform
52
+
53
+ def perform(n1, n2)
54
+ puts 'doing something'
55
+ yield if block_given?
56
+ n1 + n2
57
+ end
58
+
59
+ private
60
+
61
+ def around_perform(*args)
62
+ puts "Before: \"args\" => #{args}"
63
+ result = yield # Don't forget to execute the original implementation
64
+ puts "After: \"result\" => #{result}, \"args\" => #{args}"
65
+ end
66
+ end
67
+ ```
68
+
69
+ ## Development
70
+
71
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
72
+
73
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
74
+
75
+ ## Contributing
76
+
77
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ricardotealdi/simple_aspect.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "simple_aspect"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module SimpleAspect
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,54 @@
1
+ require "simple_aspect/version"
2
+
3
+ module SimpleAspect
4
+ require 'thread'
5
+
6
+ def self.extended(base)
7
+ base.instance_eval do
8
+ @_sa_watcher_aspects = {}
9
+ @_sa_ignoring_methods = false
10
+ @_sa_lock = Mutex.new
11
+ end
12
+ end
13
+
14
+ def aspect_around(
15
+ method, instance_around_method = instance_around_method_name(method), &block
16
+ )
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
23
+ end
24
+
25
+ def method_added(method)
26
+ aspect = @_sa_watcher_aspects[method]
27
+
28
+ return if @_sa_ignoring_methods || !aspect
29
+
30
+ @_sa_lock.synchronize do
31
+ begin
32
+ @_sa_ignoring_methods = true
33
+
34
+ orig_impl = instance_method(method)
35
+
36
+ define_method(method) do |*args, &block|
37
+ result = nil
38
+
39
+ send(aspect, *args) do
40
+ result = orig_impl.bind(self).call(*args, &block)
41
+ end
42
+
43
+ result
44
+ end
45
+ ensure
46
+ @_sa_ignoring_methods = false
47
+ end
48
+ end
49
+ end
50
+
51
+ def instance_around_method_name(method)
52
+ "_sa_around_#{method}".to_sym
53
+ end
54
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'simple_aspect/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "simple_aspect"
8
+ spec.version = SimpleAspect::VERSION
9
+ spec.authors = ["Ricardo Tealdi"]
10
+ spec.email = ["ricardo.tealdi@gmail.com"]
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"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "rspec"
22
+ spec.add_development_dependency "pry"
23
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_aspect
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ricardo Tealdi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Simple AOP implementation for Ruby
42
+ email:
43
+ - ricardo.tealdi@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - ".travis.yml"
51
+ - Gemfile
52
+ - LICENSE
53
+ - README.md
54
+ - Rakefile
55
+ - bin/console
56
+ - bin/setup
57
+ - lib/simple_aspect.rb
58
+ - lib/simple_aspect/version.rb
59
+ - simple_aspect.gemspec
60
+ homepage: https://github.com/ricardotealdi/simple_aspect
61
+ licenses: []
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.4.8
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Simple AOP implementation for Ruby
83
+ test_files: []