adviser 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/Manifest.txt +7 -0
- data/README.txt +82 -0
- data/Rakefile +22 -0
- data/bin/adviser +3 -0
- data/lib/adviser.rb +74 -0
- data/test/test_adviser.rb +8 -0
- metadata +71 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
= adviser
|
2
|
+
|
3
|
+
http://adviser.rubyforge.com
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
A very simple library to provide AOP concepts to Ruby.
|
8
|
+
|
9
|
+
== SYNOPSIS:
|
10
|
+
|
11
|
+
Here's an incredibly goofy example of how one might use Adviser.
|
12
|
+
|
13
|
+
require 'adviser'
|
14
|
+
|
15
|
+
class Speaker
|
16
|
+
def initialize
|
17
|
+
puts @intro || "*awkward pause*"
|
18
|
+
end
|
19
|
+
|
20
|
+
def main_point
|
21
|
+
puts "Eh.. I seem to have misplaced my notes."
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Let's create a teleprompter for our speaker.
|
26
|
+
|
27
|
+
advise Speaker do
|
28
|
+
before :initialize do
|
29
|
+
@intro = "Hello!"
|
30
|
+
end
|
31
|
+
|
32
|
+
instead :main_point do
|
33
|
+
puts "Ruby is awesome."
|
34
|
+
end
|
35
|
+
|
36
|
+
after :main_point do
|
37
|
+
puts "Goodbye!"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
s = Speaker.new
|
42
|
+
s.main_point
|
43
|
+
|
44
|
+
Output without adviser:
|
45
|
+
|
46
|
+
*awkward pause*
|
47
|
+
Eh.. I seem to have misplaced my notes.
|
48
|
+
|
49
|
+
Output with adviser:
|
50
|
+
|
51
|
+
Hello!
|
52
|
+
Ruby is awesome.
|
53
|
+
Goodbye!
|
54
|
+
|
55
|
+
== INSTALL:
|
56
|
+
|
57
|
+
sudo gem install adviser
|
58
|
+
|
59
|
+
== LICENSE:
|
60
|
+
|
61
|
+
(The MIT License)
|
62
|
+
|
63
|
+
Copyright (c) 2009 FIX
|
64
|
+
|
65
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
66
|
+
a copy of this software and associated documentation files (the
|
67
|
+
'Software'), to deal in the Software without restriction, including
|
68
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
69
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
70
|
+
permit persons to whom the Software is furnished to do so, subject to
|
71
|
+
the following conditions:
|
72
|
+
|
73
|
+
The above copyright notice and this permission notice shall be
|
74
|
+
included in all copies or substantial portions of the Software.
|
75
|
+
|
76
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
77
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
78
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
79
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
80
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
81
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
82
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require './lib/adviser.rb'
|
6
|
+
|
7
|
+
Hoe.new('adviser', Adviser::VERSION) do |p|
|
8
|
+
# p.rubyforge_name = 'adviserx' # if different than lowercase project name
|
9
|
+
# p.developer('FIX', 'FIX@example.com')
|
10
|
+
|
11
|
+
p.name = "adviser"
|
12
|
+
p.author = "Bryan Powell"
|
13
|
+
p.description = "A very simple library to provide AOP concepts to Ruby."
|
14
|
+
p.email = 'bryan@metabahn.com'
|
15
|
+
p.summary = "AOP For Ruby"
|
16
|
+
p.url = "http://metabahn.com"
|
17
|
+
# p.clean_globs = ['test/actual'] # Remove this directory on "rake clean"
|
18
|
+
p.remote_rdoc_dir = '' # Release to root
|
19
|
+
# p.changes = p.paragraphs_of('CHANGELOG', 0..1).join("\n\n")
|
20
|
+
end
|
21
|
+
|
22
|
+
# vim: syntax=Ruby
|
data/bin/adviser
ADDED
data/lib/adviser.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
class Adviser
|
2
|
+
VERSION = '0.0.1'
|
3
|
+
end
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def advise(object, &block)
|
7
|
+
@object = object
|
8
|
+
Proc.new(&block).call
|
9
|
+
end
|
10
|
+
|
11
|
+
def instead(method, &block)
|
12
|
+
@object.__create_instead(method, Proc.new(&block))
|
13
|
+
end
|
14
|
+
|
15
|
+
def before(method, &block)
|
16
|
+
@object.__create_before(method, Proc.new(&block))
|
17
|
+
end
|
18
|
+
|
19
|
+
def after(method, &block)
|
20
|
+
@object.__create_after(method, Proc.new(&block))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class Object
|
25
|
+
private
|
26
|
+
|
27
|
+
def self.__create_instead(method, proc)
|
28
|
+
id = __id(proc)
|
29
|
+
|
30
|
+
__alias(method, id)
|
31
|
+
define_method method, proc
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.__create_before(method, proc)
|
35
|
+
args = __args(method)
|
36
|
+
id = __id(proc)
|
37
|
+
|
38
|
+
__alias(method, id)
|
39
|
+
define_method :"__before_#{method}_#{id}", proc
|
40
|
+
class_eval %{
|
41
|
+
def #{method}#{args}
|
42
|
+
__before_#{method}_#{id}#{args}
|
43
|
+
__previous_#{method}_#{id}#{args}
|
44
|
+
end
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.__create_after(method, proc)
|
49
|
+
args = __args(method)
|
50
|
+
id = __id(proc)
|
51
|
+
|
52
|
+
__alias(method, id)
|
53
|
+
define_method :"__after_#{method}_#{id}", proc
|
54
|
+
class_eval %{
|
55
|
+
def #{method}#{args}
|
56
|
+
res = __previous_#{method}_#{id}#{args}
|
57
|
+
__after_#{method}_#{id}#{args}
|
58
|
+
res
|
59
|
+
end
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.__alias(method, id)
|
64
|
+
alias_method :"__previous_#{method}_#{id}", method
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.__args(method)
|
68
|
+
instance_method(method).arity == 0 ? '' : '(*args)'
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.__id(proc)
|
72
|
+
"%04x" % proc.object_id
|
73
|
+
end
|
74
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: adviser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bryan Powell
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-14 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.12.2
|
24
|
+
version:
|
25
|
+
description: A very simple library to provide AOP concepts to Ruby.
|
26
|
+
email: bryan@metabahn.com
|
27
|
+
executables:
|
28
|
+
- adviser
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- History.txt
|
33
|
+
- Manifest.txt
|
34
|
+
- README.txt
|
35
|
+
files:
|
36
|
+
- History.txt
|
37
|
+
- Manifest.txt
|
38
|
+
- README.txt
|
39
|
+
- Rakefile
|
40
|
+
- bin/adviser
|
41
|
+
- lib/adviser.rb
|
42
|
+
- test/test_adviser.rb
|
43
|
+
has_rdoc: true
|
44
|
+
homepage: http://metabahn.com
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options:
|
47
|
+
- --main
|
48
|
+
- README.txt
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
version:
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
version:
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project: adviser
|
66
|
+
rubygems_version: 1.3.1
|
67
|
+
signing_key:
|
68
|
+
specification_version: 2
|
69
|
+
summary: AOP For Ruby
|
70
|
+
test_files:
|
71
|
+
- test/test_adviser.rb
|