holywarez-mpt 0.1.3.15 → 0.1.3.16
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +19 -18
- data/Manifest +19 -19
- data/Rakefile +19 -8
- data/lib/event.rb +124 -120
- data/mpt.gemspec +38 -37
- data/test/security_test.rb +2 -0
- data/test/test_helper.rb +3 -0
- metadata +16 -16
- data/install_gem.bat +0 -5
- data/run_examples.bat +0 -3
data/CHANGELOG
CHANGED
@@ -1,19 +1,20 @@
|
|
1
|
-
v0.1.3.
|
2
|
-
v0.1.3.
|
3
|
-
v0.1.3.
|
4
|
-
v0.1.3.
|
5
|
-
v0.1.3.
|
6
|
-
v0.1.3.
|
7
|
-
v0.1.3.
|
8
|
-
v0.1.3.
|
9
|
-
v0.1.3.
|
10
|
-
v0.1.3.
|
11
|
-
v0.1.3.
|
12
|
-
v0.1.3.
|
13
|
-
v0.1.3.
|
14
|
-
v0.1.3.
|
15
|
-
v0.1.3.
|
16
|
-
v0.1.3
|
17
|
-
v0.1.
|
18
|
-
v0.1.
|
1
|
+
v0.1.3.16 Event.method_missing implementation
|
2
|
+
v0.1.3.15 Security.sandbox experiment
|
3
|
+
v0.1.3.14 "subscribe instance methods" bugfix
|
4
|
+
v0.1.3.13 reorganize alghoritm fixed
|
5
|
+
v0.1.3.12 subscribe class instance methods for events is now supported
|
6
|
+
v0.1.3.11 wrappable was renamed to wrapable. "wrappable" will be removed in future versions
|
7
|
+
v0.1.3.10 wrap ability without accessor
|
8
|
+
v0.1.3.9 cache_method helper
|
9
|
+
v0.1.3.8 Refactoring FilterChain array subclass
|
10
|
+
v0.1.3.7 Bug fix for clear_owner_subscribers
|
11
|
+
v0.1.3.6 Bug fix for Wrap.get default value
|
12
|
+
v0.1.3.5 Little bug fix for empty subscriber chain
|
13
|
+
v0.1.3.4 Added clear_owner_subscribers
|
14
|
+
v0.1.3.3 Added clear_event_chain support
|
15
|
+
v0.1.3.2 Added new example
|
16
|
+
v0.1.3.1 Added dependencies for gem
|
17
|
+
v0.1.3 Wrap helpers support added
|
18
|
+
v0.1.2 Instance eval with arguments is now supported for any object
|
19
|
+
v0.1.1 Sample sources updated
|
19
20
|
v0.1.0 First version of MPT gem
|
data/Manifest
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
CHANGELOG
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
examples/
|
7
|
-
examples/
|
8
|
-
examples/
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
1
|
+
CHANGELOG
|
2
|
+
examples/call_experiment.rb
|
3
|
+
examples/declarations.rb
|
4
|
+
examples/instance_eval_with_args.rb
|
5
|
+
examples/ordered_subscribers.rb
|
6
|
+
examples/run_experiments.rb
|
7
|
+
examples/unordered_subscribers.rb
|
8
|
+
examples/wrap_method_experiment.rb
|
9
|
+
lib/event.rb
|
10
|
+
lib/mpt.rb
|
11
|
+
lib/system.rb
|
12
|
+
lib/wrap.rb
|
13
|
+
LICENSE
|
14
|
+
Manifest
|
15
|
+
mpt.gemspec
|
16
|
+
Rakefile
|
17
|
+
README
|
18
|
+
test/security_test.rb
|
19
|
+
test/test_helper.rb
|
data/Rakefile
CHANGED
@@ -1,11 +1,22 @@
|
|
1
1
|
require "echoe"
|
2
|
+
|
2
3
|
Echoe.new( "mpt" ) do |p|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
p.author = ["Anatoly Lapshin", "Ilya Vesov"]
|
5
|
+
p.summary = "Monkey Patching Toolkit"
|
6
|
+
p.email = "holywarez@gmail.com"
|
7
|
+
p.url = "http://github.com/holywarez/mpt"
|
8
|
+
|
9
|
+
p.runtime_dependencies = ['activesupport', 'uuid']
|
10
|
+
p.development_dependencies = []
|
11
|
+
|
12
|
+
p.need_tar_gz = false
|
13
|
+
p.retain_gemspec = true
|
14
|
+
p.gemspec_name = 'mpt.gemspec'
|
15
|
+
p.test_pattern = ["test/**/*_test.rb"]
|
16
|
+
|
17
|
+
p.clean_pattern.push 'lib/*-*'
|
18
|
+
p.has_rdoc = true
|
19
|
+
p.rdoc_pattern = ["README", "CHANGELOG", "lib/**/*.rb"]
|
20
|
+
p.rdoc_options << "-c utf-8"
|
21
|
+
p.ignore_pattern = [".gitignore", "doc", "examples", ".idea", "coverage.data", "*.bat"]
|
11
22
|
end
|
data/lib/event.rb
CHANGED
@@ -1,120 +1,124 @@
|
|
1
|
-
|
2
|
-
class Array
|
3
|
-
def mpt_filterchain_reorganize
|
4
|
-
index = 0
|
5
|
-
while index < self.size
|
6
|
-
filter = self[index]
|
7
|
-
filter_opts = filter[:options]
|
8
|
-
unless filter_opts[:after].nil?
|
9
|
-
(self.size-1).downto(index) do |i|
|
10
|
-
fo = self[i][:options]
|
11
|
-
unless fo[:as].nil?
|
12
|
-
if fo[:as] == filter_opts[:after]
|
13
|
-
new_chain = []
|
14
|
-
new_chain += self[0..index-1] if index > 0
|
15
|
-
new_chain += [self[i]]
|
16
|
-
new_chain += self[index..i-1]
|
17
|
-
new_chain += self[i+1..self.size-1]
|
18
|
-
self.replace new_chain
|
19
|
-
index = 0
|
20
|
-
break
|
21
|
-
end # if :as matched with :after
|
22
|
-
end # unless :as is nil
|
23
|
-
end # for next items
|
24
|
-
end # unless :after is nil
|
25
|
-
index += 1
|
26
|
-
end # while index < list size
|
27
|
-
end # def reorganize
|
28
|
-
end # filter chain class
|
29
|
-
|
30
|
-
module MPT
|
31
|
-
class EventContainer
|
32
|
-
attr_accessor :event_object
|
33
|
-
|
34
|
-
def initialize( val = nil )
|
35
|
-
self.event_object = val.dup unless val.nil?
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
class Event
|
41
|
-
@@mpt_subscribers = {}
|
42
|
-
|
43
|
-
class << self
|
44
|
-
def subscribe(event_name, options = {}, &block)
|
45
|
-
channel = @@mpt_subscribers[event_name] ||= []
|
46
|
-
channel << { :options => options, :proc => block }
|
47
|
-
channel.mpt_filterchain_reorganize
|
48
|
-
end
|
49
|
-
|
50
|
-
def trigger_with_object(event_name, object, *args)
|
51
|
-
container = MPT::EventContainer.new(object)
|
52
|
-
channel = @@mpt_subscribers[event_name]
|
53
|
-
if !channel.nil? && channel.size > 0
|
54
|
-
channel.each do |subscriber|
|
55
|
-
container.instance_eval_with_args( *args, &subscriber[:proc] )
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
container.event_object
|
60
|
-
end
|
61
|
-
|
62
|
-
def trigger(event_name, *args)
|
63
|
-
trigger_with_object(event_name, nil, *args)
|
64
|
-
end
|
65
|
-
|
66
|
-
def clear_event_chain(event_name)
|
67
|
-
@@mpt_subscribers.delete(event_name)
|
68
|
-
end
|
69
|
-
|
70
|
-
def clear_owner_subscribers(owner)
|
71
|
-
@@mpt_subscribers.each_pair do |event_name, subscribers|
|
72
|
-
@@mpt_subscribers[event_name] = subscribers.select { |s| owner != s[:options][:owner] }
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
end
|
79
|
-
|
80
|
-
class
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
1
|
+
|
2
|
+
class Array
|
3
|
+
def mpt_filterchain_reorganize
|
4
|
+
index = 0
|
5
|
+
while index < self.size
|
6
|
+
filter = self[index]
|
7
|
+
filter_opts = filter[:options]
|
8
|
+
unless filter_opts[:after].nil?
|
9
|
+
(self.size-1).downto(index) do |i|
|
10
|
+
fo = self[i][:options]
|
11
|
+
unless fo[:as].nil?
|
12
|
+
if fo[:as] == filter_opts[:after]
|
13
|
+
new_chain = []
|
14
|
+
new_chain += self[0..index-1] if index > 0
|
15
|
+
new_chain += [self[i]]
|
16
|
+
new_chain += self[index..i-1]
|
17
|
+
new_chain += self[i+1..self.size-1]
|
18
|
+
self.replace new_chain
|
19
|
+
index = 0
|
20
|
+
break
|
21
|
+
end # if :as matched with :after
|
22
|
+
end # unless :as is nil
|
23
|
+
end # for next items
|
24
|
+
end # unless :after is nil
|
25
|
+
index += 1
|
26
|
+
end # while index < list size
|
27
|
+
end # def reorganize
|
28
|
+
end # filter chain class
|
29
|
+
|
30
|
+
module MPT
|
31
|
+
class EventContainer
|
32
|
+
attr_accessor :event_object
|
33
|
+
|
34
|
+
def initialize( val = nil )
|
35
|
+
self.event_object = val.dup unless val.nil?
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
class Event
|
41
|
+
@@mpt_subscribers = {}
|
42
|
+
|
43
|
+
class << self
|
44
|
+
def subscribe(event_name, options = {}, &block)
|
45
|
+
channel = @@mpt_subscribers[event_name] ||= []
|
46
|
+
channel << { :options => options, :proc => block }
|
47
|
+
channel.mpt_filterchain_reorganize
|
48
|
+
end
|
49
|
+
|
50
|
+
def trigger_with_object(event_name, object, *args)
|
51
|
+
container = MPT::EventContainer.new(object)
|
52
|
+
channel = @@mpt_subscribers[event_name]
|
53
|
+
if !channel.nil? && channel.size > 0
|
54
|
+
channel.each do |subscriber|
|
55
|
+
container.instance_eval_with_args( *args, &subscriber[:proc] )
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
container.event_object
|
60
|
+
end
|
61
|
+
|
62
|
+
def trigger(event_name, *args)
|
63
|
+
trigger_with_object(event_name, nil, *args)
|
64
|
+
end
|
65
|
+
|
66
|
+
def clear_event_chain(event_name)
|
67
|
+
@@mpt_subscribers.delete(event_name)
|
68
|
+
end
|
69
|
+
|
70
|
+
def clear_owner_subscribers(owner)
|
71
|
+
@@mpt_subscribers.each_pair do |event_name, subscribers|
|
72
|
+
@@mpt_subscribers[event_name] = subscribers.select { |s| owner != s[:options][:owner] }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def method_missing(name, *args)
|
77
|
+
self.trigger(name.to_sym, *args)
|
78
|
+
end
|
79
|
+
end # end of static section
|
80
|
+
end # end of class Event
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
class Class
|
85
|
+
def subscribe( target, options )
|
86
|
+
return if options[:for].blank?
|
87
|
+
|
88
|
+
unless self.respond_to?( :new_with_subscribe_support )
|
89
|
+
code_to_eval = <<-EOC
|
90
|
+
class << self
|
91
|
+
def register_subscribe(target, options)
|
92
|
+
es = @@event_subscribes ||= {}
|
93
|
+
est = es[options[:for]] ||= []
|
94
|
+
est << target
|
95
|
+
end
|
96
|
+
|
97
|
+
def new_with_subscribe_support(*constructor_arguments)
|
98
|
+
instance = new_without_subscribe_support(*constructor_arguments)
|
99
|
+
@@event_subscribes.each_key do |event_name|
|
100
|
+
::MPT::Event.subscribe( event_name, :owner => instance ) do |*args|
|
101
|
+
instance.send( "trigger_event", event_name, *args )
|
102
|
+
end
|
103
|
+
end
|
104
|
+
instance
|
105
|
+
end
|
106
|
+
|
107
|
+
alias_method_chain :new, :subscribe_support
|
108
|
+
end
|
109
|
+
|
110
|
+
private
|
111
|
+
def trigger_event(name, *args)
|
112
|
+
@@event_subscribes[name].each do |method_name|
|
113
|
+
self.send( method_name, *args )
|
114
|
+
end
|
115
|
+
end
|
116
|
+
EOC
|
117
|
+
|
118
|
+
self.class_eval( code_to_eval, __FILE__, __LINE__ )
|
119
|
+
end
|
120
|
+
|
121
|
+
self.register_subscribe( target, options )
|
122
|
+
|
123
|
+
end
|
124
|
+
end
|
data/mpt.gemspec
CHANGED
@@ -1,37 +1,38 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
Gem::Specification.new do |s|
|
4
|
-
s.name = %q{mpt}
|
5
|
-
s.version = "0.1.3.
|
6
|
-
|
7
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = ["Anatoly Lapshin"]
|
9
|
-
s.date = %q{2009-08-
|
10
|
-
s.description = %q{Monkey Patching Toolkit}
|
11
|
-
s.email = %q{}
|
12
|
-
s.extra_rdoc_files = ["CHANGELOG", "
|
13
|
-
s.files = ["CHANGELOG", "
|
14
|
-
s.has_rdoc = true
|
15
|
-
s.homepage = %q{}
|
16
|
-
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Mpt", "--main", "README"]
|
17
|
-
s.require_paths = ["lib"]
|
18
|
-
s.rubyforge_project = %q{mpt}
|
19
|
-
s.rubygems_version = %q{1.3.
|
20
|
-
s.summary = %q{Monkey Patching Toolkit}
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
s.add_runtime_dependency(%q<
|
29
|
-
|
30
|
-
|
31
|
-
s.add_dependency(%q<
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
s.add_dependency(%q<
|
36
|
-
|
37
|
-
end
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{mpt}
|
5
|
+
s.version = "0.1.3.16"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Anatoly Lapshin, Ilya Vesov"]
|
9
|
+
s.date = %q{2009-08-07}
|
10
|
+
s.description = %q{Monkey Patching Toolkit}
|
11
|
+
s.email = %q{holywarez@gmail.com}
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG", "lib/event.rb", "lib/mpt.rb", "lib/system.rb", "lib/wrap.rb", "README"]
|
13
|
+
s.files = ["CHANGELOG", "examples/call_experiment.rb", "examples/declarations.rb", "examples/instance_eval_with_args.rb", "examples/ordered_subscribers.rb", "examples/run_experiments.rb", "examples/unordered_subscribers.rb", "examples/wrap_method_experiment.rb", "lib/event.rb", "lib/mpt.rb", "lib/system.rb", "lib/wrap.rb", "LICENSE", "Manifest", "mpt.gemspec", "Rakefile", "README", "test/security_test.rb", "test/test_helper.rb"]
|
14
|
+
s.has_rdoc = true
|
15
|
+
s.homepage = %q{http://github.com/holywarez/mpt}
|
16
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Mpt", "--main", "README", "-c utf-8"]
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.rubyforge_project = %q{mpt}
|
19
|
+
s.rubygems_version = %q{1.3.2}
|
20
|
+
s.summary = %q{Monkey Patching Toolkit}
|
21
|
+
s.test_files = ["test/security_test.rb"]
|
22
|
+
|
23
|
+
if s.respond_to? :specification_version then
|
24
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
25
|
+
s.specification_version = 3
|
26
|
+
|
27
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
28
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
29
|
+
s.add_runtime_dependency(%q<uuid>, [">= 0"])
|
30
|
+
else
|
31
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
32
|
+
s.add_dependency(%q<uuid>, [">= 0"])
|
33
|
+
end
|
34
|
+
else
|
35
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
36
|
+
s.add_dependency(%q<uuid>, [">= 0"])
|
37
|
+
end
|
38
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: holywarez-mpt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.3.
|
4
|
+
version: 0.1.3.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Anatoly Lapshin
|
7
|
+
- Anatoly Lapshin, Ilya Vesov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-08-
|
12
|
+
date: 2009-08-07 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -33,25 +33,20 @@ dependencies:
|
|
33
33
|
version: "0"
|
34
34
|
version:
|
35
35
|
description: Monkey Patching Toolkit
|
36
|
-
email:
|
36
|
+
email: holywarez@gmail.com
|
37
37
|
executables: []
|
38
38
|
|
39
39
|
extensions: []
|
40
40
|
|
41
41
|
extra_rdoc_files:
|
42
42
|
- CHANGELOG
|
43
|
-
- LICENSE
|
44
|
-
- README
|
45
43
|
- lib/event.rb
|
46
44
|
- lib/mpt.rb
|
47
45
|
- lib/system.rb
|
48
46
|
- lib/wrap.rb
|
47
|
+
- README
|
49
48
|
files:
|
50
49
|
- CHANGELOG
|
51
|
-
- LICENSE
|
52
|
-
- Manifest
|
53
|
-
- README
|
54
|
-
- Rakefile
|
55
50
|
- examples/call_experiment.rb
|
56
51
|
- examples/declarations.rb
|
57
52
|
- examples/instance_eval_with_args.rb
|
@@ -59,15 +54,19 @@ files:
|
|
59
54
|
- examples/run_experiments.rb
|
60
55
|
- examples/unordered_subscribers.rb
|
61
56
|
- examples/wrap_method_experiment.rb
|
62
|
-
- install_gem.bat
|
63
57
|
- lib/event.rb
|
64
58
|
- lib/mpt.rb
|
65
59
|
- lib/system.rb
|
66
60
|
- lib/wrap.rb
|
61
|
+
- LICENSE
|
62
|
+
- Manifest
|
67
63
|
- mpt.gemspec
|
68
|
-
-
|
64
|
+
- Rakefile
|
65
|
+
- README
|
66
|
+
- test/security_test.rb
|
67
|
+
- test/test_helper.rb
|
69
68
|
has_rdoc: true
|
70
|
-
homepage:
|
69
|
+
homepage: http://github.com/holywarez/mpt
|
71
70
|
licenses:
|
72
71
|
post_install_message:
|
73
72
|
rdoc_options:
|
@@ -77,6 +76,7 @@ rdoc_options:
|
|
77
76
|
- Mpt
|
78
77
|
- --main
|
79
78
|
- README
|
79
|
+
- -c utf-8
|
80
80
|
require_paths:
|
81
81
|
- lib
|
82
82
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -96,7 +96,7 @@ requirements: []
|
|
96
96
|
rubyforge_project: mpt
|
97
97
|
rubygems_version: 1.3.5
|
98
98
|
signing_key:
|
99
|
-
specification_version:
|
99
|
+
specification_version: 3
|
100
100
|
summary: Monkey Patching Toolkit
|
101
|
-
test_files:
|
102
|
-
|
101
|
+
test_files:
|
102
|
+
- test/security_test.rb
|
data/install_gem.bat
DELETED
data/run_examples.bat
DELETED