serializable_proc 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.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/HISTORY.txt +4 -0
- data/LICENSE +20 -0
- data/README.rdoc +132 -0
- data/Rakefile +136 -0
- data/VERSION +1 -0
- data/lib/serializable_proc/binding.rb +53 -0
- data/lib/serializable_proc/marshalable.rb +51 -0
- data/lib/serializable_proc/parsers/pt.rb +16 -0
- data/lib/serializable_proc/parsers/rp.rb +93 -0
- data/lib/serializable_proc/parsers.rb +8 -0
- data/lib/serializable_proc/sandboxer.rb +24 -0
- data/lib/serializable_proc.rb +169 -0
- data/spec/extracting_bound_variables_spec.rb +99 -0
- data/spec/initializing_errors_spec.rb +95 -0
- data/spec/marshalling_spec.rb +51 -0
- data/spec/multiple_arities_serializable_proc_spec.rb +159 -0
- data/spec/one_arity_serializable_proc_spec.rb +159 -0
- data/spec/optional_arity_serializable_proc_spec.rb +160 -0
- data/spec/proc_like_spec.rb +191 -0
- data/spec/spec_helper.rb +100 -0
- data/spec/zero_arity_serializable_proc_spec.rb +159 -0
- metadata +127 -0
@@ -0,0 +1,159 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe 'Zero arity serializable proc' do
|
4
|
+
|
5
|
+
extend SerializableProc::Spec::Helpers
|
6
|
+
|
7
|
+
expected_file = File.expand_path(__FILE__)
|
8
|
+
expected_code = "lambda { [\"a\", \"b\"].map { |lvar_x| puts(lvar_x) } }"
|
9
|
+
|
10
|
+
should_handle_proc_variable expected_file, expected_code, {
|
11
|
+
# ////////////////////////////////////////////////////////////////////////
|
12
|
+
# >> Always newlinling
|
13
|
+
# ////////////////////////////////////////////////////////////////////////
|
14
|
+
__LINE__ =>
|
15
|
+
lambda do
|
16
|
+
%w{a b}.map do |x|
|
17
|
+
puts x
|
18
|
+
end
|
19
|
+
end,
|
20
|
+
__LINE__ =>
|
21
|
+
lambda {
|
22
|
+
%w{a b}.map{|x|
|
23
|
+
puts x
|
24
|
+
}
|
25
|
+
},
|
26
|
+
__LINE__ =>
|
27
|
+
proc do
|
28
|
+
%w{a b}.map do |x|
|
29
|
+
puts x
|
30
|
+
end
|
31
|
+
end,
|
32
|
+
__LINE__ =>
|
33
|
+
lambda {
|
34
|
+
%w{a b}.map{|x|
|
35
|
+
puts x
|
36
|
+
}
|
37
|
+
},
|
38
|
+
__LINE__ =>
|
39
|
+
Proc.new do
|
40
|
+
%w{a b}.map do |x|
|
41
|
+
puts x
|
42
|
+
end
|
43
|
+
end,
|
44
|
+
__LINE__ =>
|
45
|
+
Proc.new {
|
46
|
+
%w{a b}.map{|x|
|
47
|
+
puts x
|
48
|
+
}
|
49
|
+
},
|
50
|
+
# ////////////////////////////////////////////////////////////////////////
|
51
|
+
# >> Partial newlining
|
52
|
+
# ////////////////////////////////////////////////////////////////////////
|
53
|
+
__LINE__ =>
|
54
|
+
lambda do
|
55
|
+
%w{a b}.map do |x| puts x end
|
56
|
+
end,
|
57
|
+
__LINE__ =>
|
58
|
+
lambda {
|
59
|
+
%w{a b}.map{|x| puts x }
|
60
|
+
},
|
61
|
+
__LINE__ =>
|
62
|
+
proc do
|
63
|
+
%w{a b}.map do |x| puts x end
|
64
|
+
end,
|
65
|
+
__LINE__ =>
|
66
|
+
lambda {
|
67
|
+
%w{a b}.map{|x| puts x }
|
68
|
+
},
|
69
|
+
__LINE__ =>
|
70
|
+
Proc.new do
|
71
|
+
%w{a b}.map do |x| puts x end
|
72
|
+
end,
|
73
|
+
__LINE__ =>
|
74
|
+
Proc.new {
|
75
|
+
%w{a b}.map{|x| puts x }
|
76
|
+
},
|
77
|
+
# ////////////////////////////////////////////////////////////////////////
|
78
|
+
# >> No newlining
|
79
|
+
# ////////////////////////////////////////////////////////////////////////
|
80
|
+
__LINE__ =>
|
81
|
+
lambda do %w{a b}.map do |x| puts x end end,
|
82
|
+
__LINE__ =>
|
83
|
+
lambda { %w{a b}.map{|x| puts x } },
|
84
|
+
__LINE__ =>
|
85
|
+
proc do %w{a b}.map do |x| puts x end end,
|
86
|
+
__LINE__ =>
|
87
|
+
lambda { %w{a b}.map{|x| puts x } },
|
88
|
+
__LINE__ =>
|
89
|
+
Proc.new do %w{a b}.map do |x| puts x end end,
|
90
|
+
__LINE__ =>
|
91
|
+
Proc.new { %w{a b}.map{|x| puts x } },
|
92
|
+
}
|
93
|
+
|
94
|
+
should "handle block using do ... end [##{__LINE__}]" do
|
95
|
+
(
|
96
|
+
SerializableProc.new do
|
97
|
+
%w{a b}.map{|x| puts x }
|
98
|
+
end
|
99
|
+
).should.be having_expected_proc_attrs(expected_file, __LINE__ - 3, expected_code)
|
100
|
+
end
|
101
|
+
|
102
|
+
should "handle block using do ... end [##{__LINE__}]" do
|
103
|
+
(SerializableProc.new do %w{a b}.map{|x| puts x } end).
|
104
|
+
should.be having_expected_proc_attrs(expected_file, __LINE__.pred, expected_code)
|
105
|
+
end
|
106
|
+
|
107
|
+
should "handle block using { ... } [##{__LINE__}]" do
|
108
|
+
(
|
109
|
+
SerializableProc.new {
|
110
|
+
%w{a b}.map{|x| puts x }
|
111
|
+
}
|
112
|
+
).should.be having_expected_proc_attrs(expected_file, __LINE__ - 3, expected_code)
|
113
|
+
end
|
114
|
+
|
115
|
+
should "handle block using { ... } [##{__LINE__}]" do
|
116
|
+
(SerializableProc.new { %w{a b}.map{|x| puts x } }).
|
117
|
+
should.be having_expected_proc_attrs(expected_file, __LINE__.pred, expected_code)
|
118
|
+
end
|
119
|
+
|
120
|
+
should "handle fanciful initializing with lambda { ... } [##{__LINE__}]" do
|
121
|
+
(SerializableProc.new(&(lambda { %w{a b}.map{|x| puts x } }))).
|
122
|
+
should.be having_expected_proc_attrs(expected_file, __LINE__.pred, expected_code)
|
123
|
+
end
|
124
|
+
|
125
|
+
should "handle fanciful initializing with lambda do ... end [##{__LINE__}]" do
|
126
|
+
(
|
127
|
+
SerializableProc.new(&(lambda do
|
128
|
+
%w{a b}.map{|x| puts x }
|
129
|
+
end))
|
130
|
+
).should.be having_expected_proc_attrs(expected_file, __LINE__ - 3, expected_code)
|
131
|
+
end
|
132
|
+
|
133
|
+
should "handle fanciful initializing with proc { ... } [##{__LINE__}]" do
|
134
|
+
(SerializableProc.new(&(proc { %w{a b}.map{|x| puts x } }))).
|
135
|
+
should.be having_expected_proc_attrs(expected_file, __LINE__.pred, expected_code)
|
136
|
+
end
|
137
|
+
|
138
|
+
should "handle fanciful initializing with proc do ... end [##{__LINE__}]" do
|
139
|
+
(
|
140
|
+
SerializableProc.new(&(proc do
|
141
|
+
%w{a b}.map{|x| puts x }
|
142
|
+
end))
|
143
|
+
).should.be having_expected_proc_attrs(expected_file, __LINE__ - 3, expected_code)
|
144
|
+
end
|
145
|
+
|
146
|
+
should "handle fanciful initializing with Proc.new { ... } [##{__LINE__}]" do
|
147
|
+
(SerializableProc.new(&(Proc.new { %w{a b}.map{|x| puts x } }))).
|
148
|
+
should.be having_expected_proc_attrs(expected_file, __LINE__.pred, expected_code)
|
149
|
+
end
|
150
|
+
|
151
|
+
should "handle fanciful initializing with Proc.new do ... end [##{__LINE__}]" do
|
152
|
+
(
|
153
|
+
SerializableProc.new(&(Proc.new do
|
154
|
+
%w{a b}.map{|x| puts x }
|
155
|
+
end))
|
156
|
+
).should.be having_expected_proc_attrs(expected_file, __LINE__ - 3, expected_code)
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: serializable_proc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- NgTzeYang
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-08-14 00:00:00 +08:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
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
|
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 "
|
52
|
+
email: ngty77@gmail.com
|
53
|
+
executables: []
|
54
|
+
|
55
|
+
extensions: []
|
56
|
+
|
57
|
+
extra_rdoc_files:
|
58
|
+
- LICENSE
|
59
|
+
- README.rdoc
|
60
|
+
files:
|
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/marshalable.rb
|
71
|
+
- lib/serializable_proc/parsers.rb
|
72
|
+
- lib/serializable_proc/parsers/pt.rb
|
73
|
+
- lib/serializable_proc/parsers/rp.rb
|
74
|
+
- lib/serializable_proc/sandboxer.rb
|
75
|
+
- spec/extracting_bound_variables_spec.rb
|
76
|
+
- spec/initializing_errors_spec.rb
|
77
|
+
- spec/marshalling_spec.rb
|
78
|
+
- spec/multiple_arities_serializable_proc_spec.rb
|
79
|
+
- spec/one_arity_serializable_proc_spec.rb
|
80
|
+
- spec/optional_arity_serializable_proc_spec.rb
|
81
|
+
- spec/proc_like_spec.rb
|
82
|
+
- spec/spec_helper.rb
|
83
|
+
- spec/zero_arity_serializable_proc_spec.rb
|
84
|
+
has_rdoc: true
|
85
|
+
homepage: http://github.com/ngty/serializable_proc
|
86
|
+
licenses: []
|
87
|
+
|
88
|
+
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 "
|
89
|
+
rdoc_options:
|
90
|
+
- --charset=UTF-8
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
hash: 3
|
99
|
+
segments:
|
100
|
+
- 0
|
101
|
+
version: "0"
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
hash: 3
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
version: "0"
|
111
|
+
requirements: []
|
112
|
+
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 1.3.7
|
115
|
+
signing_key:
|
116
|
+
specification_version: 3
|
117
|
+
summary: Proc that can be serialized (as the name suggests)
|
118
|
+
test_files:
|
119
|
+
- spec/initializing_errors_spec.rb
|
120
|
+
- spec/extracting_bound_variables_spec.rb
|
121
|
+
- spec/one_arity_serializable_proc_spec.rb
|
122
|
+
- spec/zero_arity_serializable_proc_spec.rb
|
123
|
+
- spec/multiple_arities_serializable_proc_spec.rb
|
124
|
+
- spec/marshalling_spec.rb
|
125
|
+
- spec/optional_arity_serializable_proc_spec.rb
|
126
|
+
- spec/spec_helper.rb
|
127
|
+
- spec/proc_like_spec.rb
|