serializable_proc 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.txt +7 -0
- data/README.rdoc +3 -2
- data/VERSION +1 -1
- data/lib/serializable_proc.rb +11 -12
- data/lib/serializable_proc/isolatable.rb +30 -22
- data/lib/serializable_proc/parsers/static.rb +29 -25
- data/serializable_proc.gemspec +21 -6
- data/spec/bounded_vars/class_vars_spec.rb +21 -2
- data/spec/bounded_vars/class_vars_within_block_scope_spec.rb +9 -0
- data/spec/bounded_vars/global_vars_spec.rb +21 -2
- data/spec/bounded_vars/global_vars_within_block_scope_spec.rb +9 -0
- data/spec/bounded_vars/instance_vars_spec.rb +21 -2
- data/spec/bounded_vars/instance_vars_within_block_scope_spec.rb +9 -0
- data/spec/bounded_vars/local_vars_spec.rb +21 -2
- data/spec/bounded_vars/local_vars_within_block_scope_spec.rb +9 -0
- metadata +140 -131
data/HISTORY.txt
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
=== 0.3.1 (Aug 18, 2010)
|
2
|
+
|
3
|
+
* @@_not_isolated_vars now supports :all, which is an alias of :global + :local +
|
4
|
+
:instance + :class [#ngty]
|
5
|
+
* cleaned up monstrous code [#ngty]
|
6
|
+
|
1
7
|
=== 0.3.0 (Aug 18, 2010)
|
2
8
|
|
3
9
|
* added support for defining of custom matchers that enhances static parser to handle
|
@@ -6,6 +12,7 @@
|
|
6
12
|
* ensured subclasses of SerializableProc behaves exactly like SerializableProc [#ngty]
|
7
13
|
* partially implemented workaround to ensure the more conservative usages work, quite a
|
8
14
|
number of specs still failing though [#ngty]
|
15
|
+
* fixed buggy support for magic variables __FILE__ & __LINE__ [#ngty]
|
9
16
|
|
10
17
|
=== 0.2.0 (Aug 18, 2010)
|
11
18
|
|
data/README.rdoc
CHANGED
@@ -38,10 +38,11 @@ code block:
|
|
38
38
|
$stdout << "WakeUp !!" # $stdout is the $stdout in the execution context
|
39
39
|
end
|
40
40
|
|
41
|
-
|
41
|
+
Supported values are :global, :class, :instance, :local & :all, with :all overriding
|
42
|
+
all others. The following declares all variables as not isolatable:
|
42
43
|
|
43
44
|
s_proc = SerializableProc.new do
|
44
|
-
@@_not_isolated_vars = :
|
45
|
+
@@_not_isolated_vars = :all
|
45
46
|
...
|
46
47
|
end
|
47
48
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
data/lib/serializable_proc.rb
CHANGED
@@ -42,7 +42,7 @@ end
|
|
42
42
|
# x, @x, @@x, $x = 'lx', 'ix', 'cx', 'gx'
|
43
43
|
#
|
44
44
|
# s_proc = SerializableProc.new do
|
45
|
-
# @@_not_isolated_vars = :
|
45
|
+
# @@_not_isolated_vars = :all
|
46
46
|
# [x, @x, @@x, $x].join(', ')
|
47
47
|
# end
|
48
48
|
#
|
@@ -51,8 +51,17 @@ end
|
|
51
51
|
# # Passing Kernel.binding is required to avoid nasty surprises
|
52
52
|
# s_proc.call(binding) # >> "ly, iy, cy, gy"
|
53
53
|
#
|
54
|
+
# Supported values include :global, :class, :instance, :local & :all, with :all
|
55
|
+
# overriding all others. This can also be used as a workaround for variables that cannot
|
56
|
+
# be serialized:
|
57
|
+
#
|
58
|
+
# SerializableProc.new do
|
59
|
+
# @@_not_isolated_vars = :global # don't isolate globals
|
60
|
+
# $stdout << 'WAKE UP !!' # $stdout won't be isolated (avoid marshal error)
|
61
|
+
# end
|
62
|
+
#
|
54
63
|
# Note that it is strongly-advised to append Kernel.binding as the last parameter when
|
55
|
-
# invoking the proc to avoid unnecessary nasty surprises.
|
64
|
+
# invoking the proc to avoid unnecessary nasty surprises. (see #call for more details)
|
56
65
|
#
|
57
66
|
# #2. Marshallable
|
58
67
|
#
|
@@ -82,16 +91,6 @@ class SerializableProc
|
|
82
91
|
# def action(&block) ; SerializableProc.new(&block) ; end
|
83
92
|
# action { ... }
|
84
93
|
#
|
85
|
-
# Fine-tuning of variables isolation can be done by declaring @@_not_isolated_vars
|
86
|
-
# within the code block:
|
87
|
-
#
|
88
|
-
# SerializableProc.new do
|
89
|
-
# @@_not_isolated_vars = :global # don't isolate globals
|
90
|
-
# $stdout << 'WAKE UP !!' # $stdout won't be isolated (avoid marshal error)
|
91
|
-
# end
|
92
|
-
#
|
93
|
-
# (see #call for invoking)
|
94
|
-
#
|
95
94
|
def initialize(&block)
|
96
95
|
file, line = /^#<Proc:0x[0-9A-Fa-f]+@(.+):(\d+).*?>$/.match(block.inspect)[1..2]
|
97
96
|
@file, @line, @arity = File.expand_path(file), line.to_i, block.arity
|
@@ -4,32 +4,39 @@ class SerializableProc
|
|
4
4
|
protected
|
5
5
|
|
6
6
|
def isolated_sexp(sexp)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
eval (types = isolated_types(sexp)).empty? ? sexp.inspect : (
|
8
|
+
bypass_scoping_by_block(sexp) do |sexp_str|
|
9
|
+
# NOTE: for performance issue, we play around with the sexp string, rather
|
10
|
+
# than the actual sexp.
|
11
|
+
isolated_sexp_str_for_typed_vars(sexp_str, types)
|
12
|
+
end
|
13
|
+
)
|
14
|
+
end
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
16
|
+
def bypass_scoping_by_block(sexp)
|
17
|
+
tmp_marker = :_serializable_proc_block_scope_marker_
|
18
|
+
s_sexp = sexp.gsub(s(:scope, s(:block, SexpAny.new)), tmp_marker)
|
19
|
+
pattern = %r{^#{Regexp.quote(s_sexp.inspect).gsub(tmp_marker.inspect,'(.*?)')}$}
|
20
|
+
orig_blocks = sexp.inspect.match(pattern)[1..-1] rescue []
|
21
|
+
n_sexp_str = yield(s_sexp.inspect)
|
22
|
+
orig_blocks.inject(n_sexp_str) do |sexp_str, block_sexp_str|
|
23
|
+
sexp_str.sub(tmp_marker.inspect, block_sexp_str)
|
24
|
+
end
|
25
|
+
end
|
17
26
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
"#{n_sexp_str}#{prepend}l#{declare.sub('vdecl','asgn')}#{join}#{type}var_#{name}#{append}" :
|
22
|
-
"#{n_sexp_str}#{orig}"
|
23
|
-
t_sexp_str.sub!(orig,'')
|
24
|
-
end
|
27
|
+
def isolated_sexp_str_for_typed_vars(o_sexp_str, types)
|
28
|
+
n_sexp_str = nil
|
29
|
+
var_pattern = /^(.*?s\(:)((#{types.join('|')})(asgn|var|vdecl))(,\ :)((|@|@@|\$)([\w]+))(\)|,)/
|
25
30
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
31
|
+
while m = o_sexp_str.match(var_pattern)
|
32
|
+
orig, prepend, _, type, declare, join, var, _, name, append = m[0..-1]
|
33
|
+
n_sexp_str = isolatable?(var) ?
|
34
|
+
"#{n_sexp_str}#{prepend}l#{declare.sub('vdecl','asgn')}#{join}#{type}var_#{name}#{append}" :
|
35
|
+
"#{n_sexp_str}#{orig}"
|
36
|
+
o_sexp_str.sub!(orig,'')
|
30
37
|
end
|
31
38
|
|
32
|
-
|
39
|
+
"#{n_sexp_str}#{o_sexp_str}"
|
33
40
|
end
|
34
41
|
|
35
42
|
def isolated_var(var)
|
@@ -47,7 +54,8 @@ class SerializableProc
|
|
47
54
|
types.map{|t| t[0].chr }
|
48
55
|
else
|
49
56
|
sexp_str = Sexp.from_array(diff).inspect
|
50
|
-
|
57
|
+
sexp_str.include?("s(:lit, :all)") ? [] :
|
58
|
+
types.map{|t| t[0].chr unless sexp_str.include?("s(:lit, :#{t})") }.compact
|
51
59
|
end
|
52
60
|
end
|
53
61
|
|
@@ -53,43 +53,47 @@ class SerializableProc
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def raw_sexp_and_marker
|
56
|
-
line = @line
|
57
56
|
begin
|
58
|
-
raw_sexp_and_marker_by_lineno(@line
|
57
|
+
raw_sexp_and_marker_by_lineno(@line)
|
59
58
|
rescue CannotAnalyseCodeError
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
raise $!
|
65
|
-
end
|
59
|
+
# NOTE: Tmp fix for JRuby's buggy line-numbering within Proc#inspect
|
60
|
+
RUBY_PLATFORM =~ /java/i ? (@line += 1 ; retry) : raise($!)
|
61
|
+
ensure
|
62
|
+
@raw_code = nil
|
66
63
|
end
|
67
64
|
end
|
68
65
|
|
69
66
|
def raw_sexp_and_marker_by_lineno(lineno)
|
70
|
-
# TODO: Ugly chunk, need some lovely cleanup !!
|
71
67
|
(%W{#{@klass}\.new lambda|proc|Proc\.new} + matchers).each do |declarative|
|
72
|
-
|
73
|
-
|
74
|
-
lines1, lines2 = [(0 .. (lineno - 2)), (lineno.pred .. -1)].map{|r| raw[r] }
|
75
|
-
prepend, type, block_start, append = lines2[0].match(regexp)[2..5] rescue next
|
76
|
-
|
77
|
-
if lines2[0] =~ /^(.*?\W)?(#{declarative})(\W.*?\W(#{declarative}))+(\W.*)?$/
|
78
|
-
msg = "Static code analysis can only handle single occurrence of '%s' per line !!" %
|
79
|
-
declarative.split('|').join("'/'")
|
80
|
-
raise CannotAnalyseCodeError.new(msg)
|
81
|
-
elsif lines2[0] =~ /^(.*?\W)?(#{declarative})(\W.*)?$/
|
82
|
-
marker = "__serializable_proc_marker_#{lineno}__"
|
83
|
-
line = "#{prepend}proc#{block_start} #{marker}; #{append}"
|
84
|
-
lines = lines1.join + line + lines2[1..-1].join
|
85
|
-
return [RUBY_PARSER.parse(lines, @file).inspect, marker]
|
86
|
-
end
|
68
|
+
ensure_no_repeated_occurrence(lineno, declarative)
|
69
|
+
args = raw_sexp_and_marker_args(lineno, declarative) and return args
|
87
70
|
end
|
88
71
|
raise CannotAnalyseCodeError.new('Cannot find specified initializer !!')
|
89
72
|
end
|
90
73
|
|
74
|
+
def ensure_no_repeated_occurrence(lineno, declarative)
|
75
|
+
if raw_code[lineno.pred] =~ /^(.*?\W)?(#{declarative})(\W.*?\W(#{declarative}))+(\W.*)?$/
|
76
|
+
msg = "Static code analysis can only handle single occurrence of '%s' per line !!" %
|
77
|
+
declarative.split('|').join("'/'")
|
78
|
+
raise CannotAnalyseCodeError.new(msg)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def raw_sexp_and_marker_args(lineno, declarative)
|
83
|
+
begin
|
84
|
+
raise if (line = raw_code[lineno.pred]) !~ /^(.*?\W)?(#{declarative})(\W.*)?$/
|
85
|
+
regexp = /^((.*?)(#{declarative})(\s*(?:do|\{)\s*(?:\|(?:[^\|]*)\|\s*)?)(.*)?)$/m
|
86
|
+
prepend, type, block_start, append = line.match(regexp)[2..5]
|
87
|
+
marker = "__serializable_proc_marker_#{lineno}__"
|
88
|
+
raw_code[lineno.pred] = "#{prepend}proc#{block_start} #{marker}; #{append}"
|
89
|
+
[RUBY_PARSER.parse(raw_code.join, @file).inspect, marker]
|
90
|
+
rescue
|
91
|
+
nil
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
91
95
|
def raw_code
|
92
|
-
File.readlines(@file)
|
96
|
+
@raw_code ||= File.readlines(@file)
|
93
97
|
end
|
94
98
|
|
95
99
|
end
|
data/serializable_proc.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{serializable_proc}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["NgTzeYang"]
|
@@ -72,13 +72,27 @@ Gem::Specification.new do |s|
|
|
72
72
|
"spec/spec_helper.rb"
|
73
73
|
]
|
74
74
|
s.homepage = %q{http://github.com/ngty/serializable_proc}
|
75
|
+
s.post_install_message = %q{
|
76
|
+
/////////////////////////////////////////////////////////////////////////////////
|
77
|
+
|
78
|
+
** SerializableProc **
|
79
|
+
|
80
|
+
You are installing SerializableProc on a ruby platform & version that supports
|
81
|
+
ParseTree. With ParseTree, u can enjoy better performance of SerializableProc,
|
82
|
+
as well as other dynamic code analysis goodness, as compared to the default
|
83
|
+
implementation using RubyParser's less flexible static code analysis.
|
84
|
+
|
85
|
+
Anyway, u have been informed, SerializableProc will fallback on its default
|
86
|
+
implementation using RubyParser.
|
87
|
+
|
88
|
+
/////////////////////////////////////////////////////////////////////////////////
|
89
|
+
}
|
75
90
|
s.rdoc_options = ["--charset=UTF-8"]
|
76
91
|
s.require_paths = ["lib"]
|
77
|
-
s.rubygems_version = %q{1.3.
|
92
|
+
s.rubygems_version = %q{1.3.7}
|
78
93
|
s.summary = %q{Proc that can be serialized (as the name suggests)}
|
79
94
|
s.test_files = [
|
80
|
-
"spec/
|
81
|
-
"spec/proc_like/extras_spec.rb",
|
95
|
+
"spec/proc_like/extras_spec.rb",
|
82
96
|
"spec/proc_like/invoking_with_local_vars_spec.rb",
|
83
97
|
"spec/proc_like/invoking_with_instance_vars_spec.rb",
|
84
98
|
"spec/proc_like/invoking_with_class_vars_spec.rb",
|
@@ -110,14 +124,15 @@ Gem::Specification.new do |s|
|
|
110
124
|
"spec/bounded_vars/local_vars_spec.rb",
|
111
125
|
"spec/bounded_vars/global_vars_spec.rb",
|
112
126
|
"spec/bounded_vars/instance_vars_spec.rb",
|
113
|
-
"spec/bounded_vars/class_vars_within_block_scope_spec.rb"
|
127
|
+
"spec/bounded_vars/class_vars_within_block_scope_spec.rb",
|
128
|
+
"spec/spec_helper.rb"
|
114
129
|
]
|
115
130
|
|
116
131
|
if s.respond_to? :specification_version then
|
117
132
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
118
133
|
s.specification_version = 3
|
119
134
|
|
120
|
-
if Gem::Version.new(Gem::
|
135
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
121
136
|
s.add_runtime_dependency(%q<ruby2ruby>, [">= 1.2.4"])
|
122
137
|
s.add_development_dependency(%q<bacon>, [">= 0"])
|
123
138
|
else
|
@@ -27,7 +27,16 @@ describe 'Extracting class vars' do
|
|
27
27
|
@@x, @@y = 'awe', 'some'
|
28
28
|
should_have_empty_binding \
|
29
29
|
SerializableProc.new {
|
30
|
-
@@_not_isolated_vars = :class
|
30
|
+
@@_not_isolated_vars = :class
|
31
|
+
@@x + @@y
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
should 'not handle outer-scoped ones if @@_not_isolated_vars includes :all' do
|
36
|
+
@@x, @@y = 'awe', 'some'
|
37
|
+
should_have_empty_binding \
|
38
|
+
SerializableProc.new {
|
39
|
+
@@_not_isolated_vars = :all
|
31
40
|
@@x + @@y
|
32
41
|
}
|
33
42
|
end
|
@@ -36,7 +45,17 @@ describe 'Extracting class vars' do
|
|
36
45
|
@@x, @@y = 'awe', 'some'
|
37
46
|
should_have_empty_binding \
|
38
47
|
SerializableProc.new {
|
39
|
-
@@_not_isolated_vars = :class
|
48
|
+
@@_not_isolated_vars = :class
|
49
|
+
@@z = 'wonder'
|
50
|
+
%w{a b}.each{ puts @@z, @@x, @@y }
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
should "not handle inner-scoped ones if @@_not_isolated_vars includes :all" do
|
55
|
+
@@x, @@y = 'awe', 'some'
|
56
|
+
should_have_empty_binding \
|
57
|
+
SerializableProc.new {
|
58
|
+
@@_not_isolated_vars = :all
|
40
59
|
@@z = 'wonder'
|
41
60
|
%w{a b}.each{ puts @@z, @@x, @@y }
|
42
61
|
}
|
@@ -19,6 +19,15 @@ describe 'Extracting class vars within block scope' do
|
|
19
19
|
}
|
20
20
|
end
|
21
21
|
|
22
|
+
should "not handle if @@_not_isolated_vars includes :all" do
|
23
|
+
@@x = 'ox'
|
24
|
+
should_have_empty_binding \
|
25
|
+
SerializableProc.new {
|
26
|
+
@@_not_isolated_vars = :all
|
27
|
+
def test ; @@x = 'cx' ; end
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
22
31
|
should "not handle if @@_not_isolated_vars excludes :class" do
|
23
32
|
@@x = 'ox'
|
24
33
|
should_have_empty_binding \
|
@@ -27,7 +27,16 @@ describe 'Extracting global vars' do
|
|
27
27
|
$x, $y = 'awe', 'some'
|
28
28
|
should_have_empty_binding \
|
29
29
|
SerializableProc.new {
|
30
|
-
@@_not_isolated_vars = :global
|
30
|
+
@@_not_isolated_vars = :global
|
31
|
+
$x + $y
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
should 'not handle outer-scoped ones if @@_not_isolated_vars includes :all' do
|
36
|
+
$x, $y = 'awe', 'some'
|
37
|
+
should_have_empty_binding \
|
38
|
+
SerializableProc.new {
|
39
|
+
@@_not_isolated_vars = :all
|
31
40
|
$x + $y
|
32
41
|
}
|
33
42
|
end
|
@@ -36,7 +45,17 @@ describe 'Extracting global vars' do
|
|
36
45
|
$x, $y = 'awe', 'some'
|
37
46
|
should_have_empty_binding \
|
38
47
|
SerializableProc.new {
|
39
|
-
@@_not_isolated_vars = :global
|
48
|
+
@@_not_isolated_vars = :global
|
49
|
+
$z = 'wonder'
|
50
|
+
%w{a b}.each{ puts $z, $x, $y }
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
should "not handle inner-scoped ones if @@_not_isolated_vars includes :all" do
|
55
|
+
$x, $y = 'awe', 'some'
|
56
|
+
should_have_empty_binding \
|
57
|
+
SerializableProc.new {
|
58
|
+
@@_not_isolated_vars = :all
|
40
59
|
$z = 'wonder'
|
41
60
|
%w{a b}.each{ puts $z, $x, $y }
|
42
61
|
}
|
@@ -19,6 +19,15 @@ describe 'Extracting global vars within block scope' do
|
|
19
19
|
}
|
20
20
|
end
|
21
21
|
|
22
|
+
should "not handle if @@_not_isolated_vars includes :all" do
|
23
|
+
$x = 'ox'
|
24
|
+
should_have_empty_binding \
|
25
|
+
SerializableProc.new {
|
26
|
+
@@_not_isolated_vars = :all
|
27
|
+
def test ; $x = 'gx' ; end
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
22
31
|
should "not handle if @@_not_isolated_vars excludes :global" do
|
23
32
|
$x = 'ox'
|
24
33
|
should_have_empty_binding \
|
@@ -27,7 +27,16 @@ describe 'Extracting instance vars' do
|
|
27
27
|
@x, @y = 'awe', 'some'
|
28
28
|
should_have_empty_binding \
|
29
29
|
SerializableProc.new {
|
30
|
-
@@_not_isolated_vars = :instance
|
30
|
+
@@_not_isolated_vars = :instance
|
31
|
+
@x + @y
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
should 'not handle outer-scoped ones if @@_not_isolated_vars includes :all' do
|
36
|
+
@x, @y = 'awe', 'some'
|
37
|
+
should_have_empty_binding \
|
38
|
+
SerializableProc.new {
|
39
|
+
@@_not_isolated_vars = :all
|
31
40
|
@x + @y
|
32
41
|
}
|
33
42
|
end
|
@@ -36,7 +45,17 @@ describe 'Extracting instance vars' do
|
|
36
45
|
@x, @y = 'awe', 'some'
|
37
46
|
should_have_empty_binding \
|
38
47
|
SerializableProc.new {
|
39
|
-
@@_not_isolated_vars = :instance
|
48
|
+
@@_not_isolated_vars = :instance
|
49
|
+
@z = 'wonder'
|
50
|
+
%w{a b}.each{ puts @z, @x, @y }
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
should "not handle inner-scoped ones if @@_not_isolated_vars includes :all" do
|
55
|
+
@x, @y = 'awe', 'some'
|
56
|
+
should_have_empty_binding \
|
57
|
+
SerializableProc.new {
|
58
|
+
@@_not_isolated_vars = :all
|
40
59
|
@z = 'wonder'
|
41
60
|
%w{a b}.each{ puts @z, @x, @y }
|
42
61
|
}
|
@@ -19,6 +19,15 @@ describe 'Extracting instance vars within block scope' do
|
|
19
19
|
}
|
20
20
|
end
|
21
21
|
|
22
|
+
should "not handle if @@_not_isolated_vars includes :all" do
|
23
|
+
@x = 'ox'
|
24
|
+
should_have_empty_binding \
|
25
|
+
SerializableProc.new {
|
26
|
+
@@_not_isolated_vars = :all
|
27
|
+
def test ; @x = 'ix' ; end
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
22
31
|
should "not handle if @@_not_isolated_vars excludes :instance" do
|
23
32
|
@x = 'ox'
|
24
33
|
should_have_empty_binding \
|
@@ -27,7 +27,16 @@ describe 'Extracting local vars' do
|
|
27
27
|
x, y = 'awe', 'some'
|
28
28
|
should_have_empty_binding \
|
29
29
|
SerializableProc.new {
|
30
|
-
@@_not_isolated_vars = :local
|
30
|
+
@@_not_isolated_vars = :local
|
31
|
+
x + y
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
should 'not handle outer-scoped ones if @@_not_isolated_vars includes :all' do
|
36
|
+
x, y = 'awe', 'some'
|
37
|
+
should_have_empty_binding \
|
38
|
+
SerializableProc.new {
|
39
|
+
@@_not_isolated_vars = :all
|
31
40
|
x + y
|
32
41
|
}
|
33
42
|
end
|
@@ -36,7 +45,17 @@ describe 'Extracting local vars' do
|
|
36
45
|
x, y = 'awe', 'some'
|
37
46
|
should_have_empty_binding \
|
38
47
|
SerializableProc.new {
|
39
|
-
@@_not_isolated_vars = :local
|
48
|
+
@@_not_isolated_vars = :local
|
49
|
+
z = 'wonder'
|
50
|
+
%w{a b}.each{ puts z, x, y }
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
should "not handle inner-scoped ones if @@_not_isolated_vars includes :all" do
|
55
|
+
x, y = 'awe', 'some'
|
56
|
+
should_have_empty_binding \
|
57
|
+
SerializableProc.new {
|
58
|
+
@@_not_isolated_vars = :all
|
40
59
|
z = 'wonder'
|
41
60
|
%w{a b}.each{ puts z, x, y }
|
42
61
|
}
|
@@ -19,6 +19,15 @@ describe 'Extracting local vars within block scope' do
|
|
19
19
|
}
|
20
20
|
end
|
21
21
|
|
22
|
+
should "not handle if @@_mingle_vars includes :all" do
|
23
|
+
x = 'ox'
|
24
|
+
should_have_empty_binding \
|
25
|
+
SerializableProc.new {
|
26
|
+
@@_mingle_vars = :all
|
27
|
+
def test ; x = 'lx' ; end
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
22
31
|
should "not handle if @@_mingle_vars excludes :local" do
|
23
32
|
x = 'ox'
|
24
33
|
should_have_empty_binding \
|
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serializable_proc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 17
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
version: 0.3.
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
- 1
|
10
|
+
version: 0.3.1
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
|
-
|
13
|
+
- NgTzeYang
|
13
14
|
autorequire:
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
@@ -17,32 +18,36 @@ cert_chain: []
|
|
17
18
|
date: 2010-08-18 00:00:00 +08:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: ruby2ruby
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 23
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 2
|
33
|
+
- 4
|
34
|
+
version: 1.2.4
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: bacon
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
version: "0"
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
46
51
|
description: "\n Give & take, serializing a ruby proc is possible, though not a perfect one.\n Requires either ParseTree (faster) or RubyParser (& Ruby2Ruby).\n "
|
47
52
|
email: ngty77@gmail.com
|
48
53
|
executables: []
|
@@ -50,121 +55,125 @@ executables: []
|
|
50
55
|
extensions: []
|
51
56
|
|
52
57
|
extra_rdoc_files:
|
53
|
-
|
54
|
-
|
58
|
+
- LICENSE
|
59
|
+
- README.rdoc
|
55
60
|
files:
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
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
|
-
|
61
|
+
- .document
|
62
|
+
- .gitignore
|
63
|
+
- HISTORY.txt
|
64
|
+
- LICENSE
|
65
|
+
- README.rdoc
|
66
|
+
- Rakefile
|
67
|
+
- VERSION
|
68
|
+
- lib/serializable_proc.rb
|
69
|
+
- lib/serializable_proc/binding.rb
|
70
|
+
- lib/serializable_proc/fixes.rb
|
71
|
+
- lib/serializable_proc/isolatable.rb
|
72
|
+
- lib/serializable_proc/marshalable.rb
|
73
|
+
- lib/serializable_proc/parsers.rb
|
74
|
+
- lib/serializable_proc/parsers/dynamic.rb
|
75
|
+
- lib/serializable_proc/parsers/static.rb
|
76
|
+
- serializable_proc.gemspec
|
77
|
+
- spec/bounded_vars/class_vars_spec.rb
|
78
|
+
- spec/bounded_vars/class_vars_within_block_scope_spec.rb
|
79
|
+
- spec/bounded_vars/errors_spec.rb
|
80
|
+
- spec/bounded_vars/global_vars_spec.rb
|
81
|
+
- spec/bounded_vars/global_vars_within_block_scope_spec.rb
|
82
|
+
- spec/bounded_vars/instance_vars_spec.rb
|
83
|
+
- spec/bounded_vars/instance_vars_within_block_scope_spec.rb
|
84
|
+
- spec/bounded_vars/local_vars_spec.rb
|
85
|
+
- spec/bounded_vars/local_vars_within_block_scope_spec.rb
|
86
|
+
- spec/code_block/errors_spec.rb
|
87
|
+
- spec/code_block/magic_vars_spec.rb
|
88
|
+
- spec/code_block/multiple_arities_spec.rb
|
89
|
+
- spec/code_block/optional_arity_spec.rb
|
90
|
+
- spec/code_block/renaming_vars_spec.rb
|
91
|
+
- spec/code_block/single_arity_spec.rb
|
92
|
+
- spec/code_block/zero_arity_spec.rb
|
93
|
+
- spec/extending/new_matcher_w_multiple_arities_spec.rb
|
94
|
+
- spec/extending/new_matcher_w_optional_arity_spec.rb
|
95
|
+
- spec/extending/new_matcher_w_single_arity_spec.rb
|
96
|
+
- spec/extending/new_matcher_w_zero_arity_spec.rb
|
97
|
+
- spec/extending/spec_helper.rb
|
98
|
+
- spec/extending/subclassing_w_multiple_arities_spec.rb
|
99
|
+
- spec/extending/subclassing_w_optional_arity_spec.rb
|
100
|
+
- spec/extending/subclassing_w_single_arity_spec.rb
|
101
|
+
- spec/extending/subclassing_w_zero_arity_spec.rb
|
102
|
+
- spec/proc_like/extras_spec.rb
|
103
|
+
- spec/proc_like/invoking_with_args_spec.rb
|
104
|
+
- spec/proc_like/invoking_with_class_vars_spec.rb
|
105
|
+
- spec/proc_like/invoking_with_global_vars_spec.rb
|
106
|
+
- spec/proc_like/invoking_with_instance_vars_spec.rb
|
107
|
+
- spec/proc_like/invoking_with_local_vars_spec.rb
|
108
|
+
- spec/proc_like/marshalling_spec.rb
|
109
|
+
- spec/proc_like/others_spec.rb
|
110
|
+
- spec/spec_helper.rb
|
106
111
|
has_rdoc: true
|
107
112
|
homepage: http://github.com/ngty/serializable_proc
|
108
113
|
licenses: []
|
109
114
|
|
110
|
-
post_install_message:
|
115
|
+
post_install_message: "\n /////////////////////////////////////////////////////////////////////////////////\n\n ** SerializableProc **\n\n You are installing SerializableProc on a ruby platform & version that supports\n ParseTree. With ParseTree, u can enjoy better performance of SerializableProc,\n as well as other dynamic code analysis goodness, as compared to the default\n implementation using RubyParser's less flexible static code analysis.\n\n Anyway, u have been informed, SerializableProc will fallback on its default\n implementation using RubyParser.\n\n /////////////////////////////////////////////////////////////////////////////////\n "
|
111
116
|
rdoc_options:
|
112
|
-
|
117
|
+
- --charset=UTF-8
|
113
118
|
require_paths:
|
114
|
-
|
119
|
+
- lib
|
115
120
|
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
116
122
|
requirements:
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
hash: 3
|
126
|
+
segments:
|
127
|
+
- 0
|
128
|
+
version: "0"
|
122
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
123
131
|
requirements:
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
hash: 3
|
135
|
+
segments:
|
136
|
+
- 0
|
137
|
+
version: "0"
|
129
138
|
requirements: []
|
130
139
|
|
131
140
|
rubyforge_project:
|
132
|
-
rubygems_version: 1.3.
|
141
|
+
rubygems_version: 1.3.7
|
133
142
|
signing_key:
|
134
143
|
specification_version: 3
|
135
144
|
summary: Proc that can be serialized (as the name suggests)
|
136
145
|
test_files:
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
146
|
+
- spec/proc_like/extras_spec.rb
|
147
|
+
- spec/proc_like/invoking_with_local_vars_spec.rb
|
148
|
+
- spec/proc_like/invoking_with_instance_vars_spec.rb
|
149
|
+
- spec/proc_like/invoking_with_class_vars_spec.rb
|
150
|
+
- spec/proc_like/invoking_with_args_spec.rb
|
151
|
+
- spec/proc_like/others_spec.rb
|
152
|
+
- spec/proc_like/invoking_with_global_vars_spec.rb
|
153
|
+
- spec/proc_like/marshalling_spec.rb
|
154
|
+
- spec/code_block/magic_vars_spec.rb
|
155
|
+
- spec/code_block/multiple_arities_spec.rb
|
156
|
+
- spec/code_block/zero_arity_spec.rb
|
157
|
+
- spec/code_block/errors_spec.rb
|
158
|
+
- spec/code_block/renaming_vars_spec.rb
|
159
|
+
- spec/code_block/single_arity_spec.rb
|
160
|
+
- spec/code_block/optional_arity_spec.rb
|
161
|
+
- spec/extending/subclassing_w_optional_arity_spec.rb
|
162
|
+
- spec/extending/subclassing_w_single_arity_spec.rb
|
163
|
+
- spec/extending/new_matcher_w_multiple_arities_spec.rb
|
164
|
+
- spec/extending/subclassing_w_zero_arity_spec.rb
|
165
|
+
- spec/extending/new_matcher_w_single_arity_spec.rb
|
166
|
+
- spec/extending/subclassing_w_multiple_arities_spec.rb
|
167
|
+
- spec/extending/new_matcher_w_optional_arity_spec.rb
|
168
|
+
- spec/extending/new_matcher_w_zero_arity_spec.rb
|
169
|
+
- spec/extending/spec_helper.rb
|
170
|
+
- spec/bounded_vars/global_vars_within_block_scope_spec.rb
|
171
|
+
- spec/bounded_vars/instance_vars_within_block_scope_spec.rb
|
172
|
+
- spec/bounded_vars/errors_spec.rb
|
173
|
+
- spec/bounded_vars/local_vars_within_block_scope_spec.rb
|
174
|
+
- spec/bounded_vars/class_vars_spec.rb
|
175
|
+
- spec/bounded_vars/local_vars_spec.rb
|
176
|
+
- spec/bounded_vars/global_vars_spec.rb
|
177
|
+
- spec/bounded_vars/instance_vars_spec.rb
|
178
|
+
- spec/bounded_vars/class_vars_within_block_scope_spec.rb
|
179
|
+
- spec/spec_helper.rb
|