aspekt 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +123 -0
- data/Rakefile +38 -0
- metadata +13 -11
data/README.md
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
Usage
|
2
|
+
=====
|
3
|
+
|
4
|
+
|
5
|
+
Methods you should be using
|
6
|
+
---------------------------
|
7
|
+
|
8
|
+
Although *Aspekt* consists of 4 classes and 2 modules, you should be using directly only 3 methods which API will never change:
|
9
|
+
|
10
|
+
* #before (Aspekt::Helpers::ShorthandMethods#before)
|
11
|
+
* #after (Aspekt::Helpers::ShorthandMethods#after)
|
12
|
+
* #around (Aspekt::Helpers::ShorthandMethods#around)
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
before|after|around ([instance(s)|type(s): Symbol|Regexp|Object|Array<Symbol|Regexp|Object>],) method(s): Symbol|Regexp|Array<Symbol|Regexp> do |joinpoint|
|
16
|
+
# what to do ...
|
17
|
+
# in case of around, `joinpoint.proceed` has to be called
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
* If instance or type is not specified, type: self is assumed.
|
22
|
+
* If you want, you can overwrite them and use them in your application as you want... Or you just create around advice for them and change arguments order as you like.
|
23
|
+
|
24
|
+
|
25
|
+
Example #1: In class body
|
26
|
+
-------------------------
|
27
|
+
```ruby
|
28
|
+
class Example
|
29
|
+
def one; end
|
30
|
+
def two; end
|
31
|
+
def self.three; end
|
32
|
+
def self.four; end
|
33
|
+
|
34
|
+
before method: :one do
|
35
|
+
puts "before method one"
|
36
|
+
end
|
37
|
+
|
38
|
+
after({type: self, methods: [:one, :two]}, {instance: self, method: :three}) do |joinpoint|
|
39
|
+
puts "method #{joinpoint[:method]} was called on #{self} with arguments #{joinpoint[:args]}"
|
40
|
+
end
|
41
|
+
|
42
|
+
around instance: self, method: /thr/ do |joinpoint|
|
43
|
+
puts "Before around #{joinpoint}"
|
44
|
+
result = joinpoint.proceed # calling orginal method
|
45
|
+
puts "After around #{joinpoint}"
|
46
|
+
result # return orginal value
|
47
|
+
end
|
48
|
+
|
49
|
+
class<<self
|
50
|
+
before method: :four do
|
51
|
+
puts "before four"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
58
|
+
|
59
|
+
Example #2: In random place
|
60
|
+
---------------------------
|
61
|
+
```ruby
|
62
|
+
before types: [/Strin/, /Arra/], instances: [some_object, :SomeClassForSingletonMethods], methods: [/^beginning_with/, :to_mushroom] do |joinpoint|
|
63
|
+
puts joinpoint
|
64
|
+
end
|
65
|
+
```
|
66
|
+
|
67
|
+
|
68
|
+
Example #3: In aspects
|
69
|
+
----------------------
|
70
|
+
|
71
|
+
### Recommended
|
72
|
+
|
73
|
+
1. Create folder called 'aspects' in your load path.
|
74
|
+
2. Create Aspect for Concern:
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
# ./aspects/logging/exceptions.rb (parent folder of 'aspects' must be in load path):
|
78
|
+
module Aspects
|
79
|
+
module Logging
|
80
|
+
module Exceptions
|
81
|
+
|
82
|
+
after type: Exception, method: :initialize do |joinpoint|
|
83
|
+
MyLogger.log "Just threw exception #{self.class}: #{self.backtrace}"
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
```
|
90
|
+
|
91
|
+
|
92
|
+
### You could also
|
93
|
+
|
94
|
+
* Create your own logic, but you should take care, that aspects are loaded.
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
Installation
|
99
|
+
============
|
100
|
+
|
101
|
+
|
102
|
+
Using Bundler
|
103
|
+
-------------
|
104
|
+
|
105
|
+
Add to your Gemfile:
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
gem 'aspekt'
|
109
|
+
```
|
110
|
+
|
111
|
+
And run:
|
112
|
+
|
113
|
+
```bash
|
114
|
+
bundle install
|
115
|
+
```
|
116
|
+
|
117
|
+
|
118
|
+
Using gem
|
119
|
+
---------
|
120
|
+
|
121
|
+
```bash
|
122
|
+
gem install aspekt
|
123
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# documentation
|
2
|
+
namespace 'doc' do
|
3
|
+
task :generate do
|
4
|
+
puts `rm -rf ./doc`
|
5
|
+
puts `yard doc --exclude 'test' --exclude 'Rakefile' --exclude 'Gemfile'`
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
# vc
|
10
|
+
namespace 'vc' do
|
11
|
+
task :commit do
|
12
|
+
puts `git add -A`
|
13
|
+
puts `git commit -a --message="#{ENV['message']}"`
|
14
|
+
puts `git push origin development`
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# gem
|
19
|
+
namespace 'gem' do
|
20
|
+
task :build do
|
21
|
+
puts `gem build aspekt.gemspec`
|
22
|
+
end
|
23
|
+
task :push do
|
24
|
+
puts `gem push aspekt*.gem`
|
25
|
+
end
|
26
|
+
task :remove_build do
|
27
|
+
puts `rm -rf aspekt*.gem`
|
28
|
+
end
|
29
|
+
task :publish => [:build, :push, :remove_build]
|
30
|
+
end
|
31
|
+
|
32
|
+
# tests
|
33
|
+
namespace 'tests' do
|
34
|
+
task :run do
|
35
|
+
puts `rspec --color --tty`
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aspekt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-02-25 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: is_same
|
16
|
-
requirement: &
|
16
|
+
requirement: &23847920 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *23847920
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &23847460 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *23847460
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec-core
|
38
|
-
requirement: &
|
38
|
+
requirement: &23847040 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *23847040
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: yard
|
49
|
-
requirement: &
|
49
|
+
requirement: &23846620 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *23846620
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: yard-rdoc
|
60
|
-
requirement: &
|
60
|
+
requirement: &23846200 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,14 +65,16 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *23846200
|
69
69
|
description: Before, after and around method calls. Supports Regexp matching.
|
70
70
|
email: margus@tione.eu
|
71
71
|
executables: []
|
72
72
|
extensions: []
|
73
73
|
extra_rdoc_files: []
|
74
74
|
files:
|
75
|
+
- README.md
|
75
76
|
- Gemfile
|
77
|
+
- Rakefile
|
76
78
|
- lib/aspekt.rb
|
77
79
|
- lib/aspekt/object.rb
|
78
80
|
- lib/aspekt/helpers/shorthand_methods.rb
|