sourcify 0.2.3 → 0.3.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.
@@ -0,0 +1,38 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe "Proc#to_source within IRB" do
4
+
5
+ class << self
6
+
7
+ def irb_eval(string)
8
+ irb_exec(string)[-1]
9
+ end
10
+
11
+ def equal_to(expected)
12
+ lambda {|found| normalize_code(found) == normalize_code(expected) }
13
+ end
14
+
15
+ end
16
+
17
+ should 'handle basic' do
18
+ irb_eval(%Q(
19
+ x = lambda { 1+2 }
20
+ y = lambda { 2+3 }
21
+ z = lambda { 3+4 }
22
+ y.to_source
23
+ )).should.be equal_to('proc { 2+3 }')
24
+ end
25
+
26
+ should 'handle magic variable __FILE__' do
27
+ irb_eval(%Q(
28
+ lambda { __FILE__ }.to_source
29
+ )).should.be equal_to('proc { "(irb)" }')
30
+ end
31
+
32
+ should 'handle magic variable __LINE__' do
33
+ irb_eval(%Q(
34
+ lambda { __LINE__ }.to_source
35
+ )).should.be equal_to('proc { 2 }')
36
+ end
37
+
38
+ end
@@ -66,3 +66,46 @@ def capture(stdin_str = '')
66
66
  $stdin, $stdout, $stderr = $o_stdin, $o_stdout, $o_stderr
67
67
  end
68
68
  end
69
+
70
+ def irb_exec(stdin_str)
71
+ begin
72
+ require 'otaku'
73
+
74
+ Otaku.start do |data|
75
+ # Otaku takes a SerializableProc (see http://github.com/ngty/serializable_proc),
76
+ # we don't want any variables isolation
77
+ @@_not_isolated_vars = :all
78
+
79
+ # Since we are now in another process, need to explicitely require current dev sourcify
80
+ require 'lib/sourcify'
81
+
82
+ # Get a unique tmp file (what we really want is the path)
83
+ require 'tempfile'
84
+ tf = Tempfile.new('otaku')
85
+
86
+ begin
87
+ $o_stdin, $o_stdout = $stdin, $stdout # Backup the existing stdin/stdout
88
+ $stdin, $stdout = %w{in out}.map{|s| File.new("#{tf.path}~std#{s}",'w+') } # drying up
89
+ $stdin.puts [data, 'exit', ''].join("\n")
90
+ $stdin.rewind
91
+
92
+ require 'irb'
93
+ ARGV.clear # Need this to prevent IRB from blowing up
94
+ IRB.start(__FILE__)
95
+
96
+ $stdout.rewind
97
+ irb_feedback = /^ => / # irb feedback string looks like this
98
+ $stdout.readlines.join.split("\n").
99
+ grep(irb_feedback).map{|s| eval(s.sub(irb_feedback,'').strip) }
100
+ ensure
101
+ [$stdin, $stdout, tf].each{|f| File.delete(f.path) }
102
+ $stdin, $stdout = $o_stdin, $o_stdout
103
+ end
104
+ end
105
+
106
+ Otaku.process(stdin_str)
107
+
108
+ ensure
109
+ Otaku.stop
110
+ end
111
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sourcify
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
9
8
  - 3
10
- version: 0.2.3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - NgTzeYang
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-15 00:00:00 +08:00
18
+ date: 2010-09-24 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -48,12 +48,28 @@ dependencies:
48
48
  version: "0"
49
49
  type: :development
50
50
  version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: otaku
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 15
60
+ segments:
61
+ - 0
62
+ - 4
63
+ - 0
64
+ version: 0.4.0
65
+ type: :development
66
+ version_requirements: *id003
51
67
  description: ""
52
68
  email: ngty77@gmail.com
53
69
  executables: []
54
70
 
55
- extensions: []
56
-
71
+ extensions:
72
+ - ext/sourcify/extconf.rb
57
73
  extra_rdoc_files:
58
74
  - LICENSE
59
75
  - README.rdoc
@@ -82,6 +98,7 @@ files:
82
98
  - spec/proc/others_spec.rb
83
99
  - spec/proc/readme
84
100
  - spec/proc/to_sexp_variables_spec.rb
101
+ - spec/proc/to_sexp_within_irb_spec.rb
85
102
  - spec/proc/to_source_from_braced_block_w_nested_braced_block_spec.rb
86
103
  - spec/proc/to_source_from_braced_block_w_nested_hash_spec.rb
87
104
  - spec/proc/to_source_from_braced_block_wo_nesting_complication_spec.rb
@@ -104,6 +121,7 @@ files:
104
121
  - spec/proc/to_source_magic_file_var_spec.rb
105
122
  - spec/proc/to_source_magic_line_var_spec.rb
106
123
  - spec/proc/to_source_variables_spec.rb
124
+ - spec/proc/to_source_within_irb_spec.rb
107
125
  - spec/proc_scanner/block_comment_spec.rb
108
126
  - spec/proc_scanner/double_colons_spec.rb
109
127
  - spec/proc_scanner/double_quote_str_w_interpolation_spec.rb
@@ -115,6 +133,7 @@ files:
115
133
  - spec/proc_scanner/single_quote_str_spec.rb
116
134
  - spec/proc_scanner/spec_helper.rb
117
135
  - spec/spec_helper.rb
136
+ - ext/sourcify/extconf.rb
118
137
  has_rdoc: true
119
138
  homepage: http://github.com/ngty/sourcify
120
139
  licenses: []
@@ -129,10 +148,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
129
148
  requirements:
130
149
  - - ">="
131
150
  - !ruby/object:Gem::Version
132
- hash: 3
151
+ hash: 59
133
152
  segments:
134
- - 0
135
- version: "0"
153
+ - 1
154
+ - 8
155
+ - 6
156
+ version: 1.8.6
136
157
  required_rubygems_version: !ruby/object:Gem::Requirement
137
158
  none: false
138
159
  requirements:
@@ -169,10 +190,12 @@ test_files:
169
190
  - spec/proc/to_source_from_multi_do_end_blocks_w_single_match_spec.rb
170
191
  - spec/proc/to_source_from_multi_blocks_w_many_matches_spec.rb
171
192
  - spec/proc/to_source_from_multi_blocks_w_single_match_spec.rb
193
+ - spec/proc/to_sexp_within_irb_spec.rb
172
194
  - spec/proc/to_source_from_do_end_block_w_nested_module_spec.rb
173
195
  - spec/proc/to_source_from_do_end_block_w_nested_do_end_block_spec.rb
174
196
  - spec/proc/to_source_from_do_end_block_w_nested_method_spec.rb
175
197
  - spec/proc/to_source_from_do_end_block_w_nested_class_spec.rb
198
+ - spec/proc/to_source_within_irb_spec.rb
176
199
  - spec/proc/to_source_from_do_end_block_w_nested_case_spec.rb
177
200
  - spec/proc/to_source_magic_line_var_spec.rb
178
201
  - spec/proc/to_source_from_do_end_block_w_nested_literal_keyword_spec.rb