json 1.1.9 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of json might be problematic. Click here for more details.

data/CHANGES CHANGED
@@ -1,3 +1,10 @@
1
+ 2009-10-01 (1.2.0)
2
+ * fast_generate now raises an exeception for nan and infinite floats.
3
+ * On Ruby 1.8 json supports parsing of UTF-8, UTF-16BE, UTF-16LE, UTF-32BE,
4
+ and UTF-32LE JSON documents now. Under Ruby 1.9 the M17n conversion
5
+ functions are used to convert from all supported encodings. ASCII-8BIT
6
+ encoded strings are handled like all strings under Ruby 1.8 were.
7
+ * Better documentation
1
8
  2009-08-23 (1.1.9)
2
9
  * Added forgotten main doc file extra_rdoc_files.
3
10
  2009-08-23 (1.1.8)
data/README CHANGED
@@ -1,78 +1,360 @@
1
- Dependencies for Building
2
- =========================
1
+ == json - JSON Implementation for Ruby
3
2
 
4
- - You need rake to build the extensions and install them.
3
+ === Description
5
4
 
6
- You can get it from rubyforge:
7
- http://rubyforge.org/projects/rake
5
+ This is a implementation of the JSON specification according to RFC 4627
6
+ (http://www.ietf.org/rfc/rfc4627.txt). Starting from version 1.0.0 on there
7
+ will be two variants available:
8
8
 
9
- or just type
9
+ * A pure ruby variant, that relies on the iconv and the stringscan
10
+ extensions, which are both part of the ruby standard library.
11
+ * The quite a bit faster C extension variant, which is in parts implemented
12
+ in C and comes with its own unicode conversion functions and a parser
13
+ generated by the ragel state machine compiler
14
+ (http://www.cs.queensu.ca/~thurston/ragel).
10
15
 
11
- # gem install rake
16
+ Both variants of the JSON generator escape all non-ASCII and control characters
17
+ with \uXXXX escape sequences, and support UTF-16 surrogate pairs in order to be
18
+ able to generate the whole range of unicode code points. This means that
19
+ generated JSON document is encoded as UTF-8 (because ASCII is a subset of
20
+ UTF-8) and at the same time avoids decoding problems for receiving endpoints,
21
+ that don't expect UTF-8 encoded texts. On the negative side this may lead to a
22
+ bit longer strings than necessarry.
12
23
 
13
- for the installation via rubygems.
24
+ All strings, that are to be encoded as JSON strings, should be UTF-8 byte
25
+ sequences on the Ruby side. To encode raw binary strings, that aren't UTF-8
26
+ encoded, please use the to_json_raw_object method of String (which produces
27
+ an object, that contains a byte array) and decode the result on the receiving
28
+ endpoint.
14
29
 
15
- - If you want to rebuild the parser.c file or draw nice graphviz images of the
16
- state machines, you need ragel from:
17
- http://www.cs.queensu.ca/~thurston/ragel
30
+ The JSON parsers can parse UTF-8, UTF-16BE, UTF-16LE, UTF-32BE, and UTF-32LE
31
+ JSON documents under Ruby 1.8. Under Ruby 1.9 they take advantage of Ruby's
32
+ M17n features and can parse all documents which have the correct
33
+ String#encoding set. If a document string has ASCII-8BIT as an encoding the
34
+ parser attempts to figure out which of the UTF encodings from above it is and
35
+ trys to parse it.
18
36
 
19
- Installation
20
- ============
37
+ === Installation
21
38
 
22
- It's recommended to use the extension variant of JSON, because it's quite a bit
23
- faster than the pure ruby variant. If you cannot build it on your system, you
24
- can settle for the latter.
39
+ It's recommended to use the extension variant of JSON, because it's faster than
40
+ the pure ruby variant. If you cannot build it on your system, you can settle
41
+ for the latter.
25
42
 
26
43
  Just type into the command line as root:
27
44
 
28
- # rake install
45
+ # rake install
29
46
 
30
47
  The above command will build the extensions and install them on your system.
31
48
 
32
- # rake install_pure
49
+ # rake install_pure
33
50
 
34
51
  or
35
52
 
36
- # ruby install.rb
53
+ # ruby install.rb
37
54
 
38
55
  will just install the pure ruby implementation of JSON.
39
56
 
40
57
  If you use Rubygems you can type
41
58
 
42
- # gem install json
59
+ # gem install json
43
60
 
44
61
  instead, to install the newest JSON version.
45
62
 
46
63
  There is also a pure ruby json only variant of the gem, that can be installed
47
64
  with:
48
65
 
49
- # gem install json_pure
66
+ # gem install json_pure
67
+
68
+ === Compiling the extensions yourself
69
+
70
+ If you want to build the extensions yourself you need rake:
71
+
72
+ You can get it from rubyforge:
73
+ http://rubyforge.org/projects/rake
74
+
75
+ or just type
76
+
77
+ # gem install rake
78
+
79
+ for the installation via rubygems.
80
+
81
+ If you want to create the parser.c file from its parser.rl file or draw nice
82
+ graphviz images of the state machines, you need ragel from: http://www.cs.queensu.ca/~thurston/ragel
83
+
84
+
85
+ === Usage
86
+
87
+ To use JSON you can
88
+ require 'json'
89
+ to load the installed variant (either the extension 'json' or the pure
90
+ variant 'json_pure'). If you have installed the extension variant, you can
91
+ pick either the extension variant or the pure variant by typing
92
+ require 'json/ext'
93
+ or
94
+ require 'json/pure'
95
+
96
+ Now you can parse a JSON document into a ruby data structure by calling
97
+
98
+ JSON.parse(document)
99
+
100
+ If you want to generate a JSON document from a ruby data structure call
101
+ JSON.generate(data)
102
+
103
+ You can also use the pretty_generate method (which formats the output more
104
+ verbosely and nicely) or fast_generate (which doesn't do any of the security
105
+ checks generate performs, e. g. nesting deepness checks).
106
+
107
+ To create a valid JSON document you have to make sure, that the output is
108
+ embedded in either a JSON array [] or a JSON object {}. The easiest way to do
109
+ this, is by putting your values in a Ruby Array or Hash instance.
110
+
111
+ There are also the JSON and JSON[] methods which use parse on a String or
112
+ generate a JSON document from an array or hash:
113
+
114
+ document = JSON 'test' => 23 # => "{\"test\":23}"
115
+ document = JSON['test'] => 23 # => "{\"test\":23}"
116
+
117
+ and
118
+
119
+ data = JSON '{"test":23}' # => {"test"=>23}
120
+ data = JSON['{"test":23}'] # => {"test"=>23}
121
+
122
+ You can choose to load a set of common additions to ruby core's objects if
123
+ you
124
+ require 'json/add/core'
125
+
126
+ After requiring this you can, e. g., serialise/deserialise Ruby ranges:
50
127
 
51
- Testing and Examples
52
- ====================
128
+ JSON JSON(1..10) # => 1..10
53
129
 
54
- To run the tests type:
130
+ To find out how to add JSON support to other or your own classes, read the
131
+ section "More Examples" below.
55
132
 
56
- $ rake test_ext
133
+ To get the best compatibility to rails' JSON implementation, you can
134
+ require 'json/add/rails'
57
135
 
58
- This will build the extensions first and then test them.
136
+ Both of the additions attempt to require 'json' (like above) first, if it has
137
+ not been required yet.
59
138
 
60
- $ rake test_pure
139
+ === More Examples
61
140
 
62
- This will test the pure ruby extensions.
141
+ To create a JSON document from a ruby data structure, you can call
142
+ JSON.generate like that:
63
143
 
64
- There is also a small example in tools/server.rb if you want to see, how
144
+ json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
145
+ # => "[1,2,{\"a\":3.141},false,true,null,\"4..10\"]"
146
+
147
+ To get back a ruby data structure from a JSON document, you have to call
148
+ JSON.parse on it:
149
+
150
+ JSON.parse json
151
+ # => [1, 2, {"a"=>3.141}, false, true, nil, "4..10"]
152
+
153
+ Note, that the range from the original data structure is a simple
154
+ string now. The reason for this is, that JSON doesn't support ranges
155
+ or arbitrary classes. In this case the json library falls back to call
156
+ Object#to_json, which is the same as #to_s.to_json.
157
+
158
+ It's possible to add JSON support serialization to arbitrary classes by
159
+ simply implementing a more specialized version of the #to_json method, that
160
+ should return a JSON object (a hash converted to JSON with #to_json) like
161
+ this (don't forget the *a for all the arguments):
162
+
163
+ class Range
164
+ def to_json(*a)
165
+ {
166
+ 'json_class' => self.class.name, # = 'Range'
167
+ 'data' => [ first, last, exclude_end? ]
168
+ }.to_json(*a)
169
+ end
170
+ end
171
+
172
+ The hash key 'json_class' is the class, that will be asked to deserialise the
173
+ JSON representation later. In this case it's 'Range', but any namespace of
174
+ the form 'A::B' or '::A::B' will do. All other keys are arbitrary and can be
175
+ used to store the necessary data to configure the object to be deserialised.
176
+
177
+ If a the key 'json_class' is found in a JSON object, the JSON parser checks
178
+ if the given class responds to the json_create class method. If so, it is
179
+ called with the JSON object converted to a Ruby hash. So a range can
180
+ be deserialised by implementing Range.json_create like this:
181
+
182
+ class Range
183
+ def self.json_create(o)
184
+ new(*o['data'])
185
+ end
186
+ end
187
+
188
+ Now it possible to serialise/deserialise ranges as well:
189
+
190
+ json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
191
+ # => "[1,2,{\"a\":3.141},false,true,null,{\"json_class\":\"Range\",\"data\":[4,10,false]}]"
192
+ JSON.parse json
193
+ # => [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
194
+
195
+ JSON.generate always creates the shortest possible string representation of a
196
+ ruby data structure in one line. This is good for data storage or network
197
+ protocols, but not so good for humans to read. Fortunately there's also
198
+ JSON.pretty_generate (or JSON.pretty_generate) that creates a more readable
199
+ output:
200
+
201
+ puts JSON.pretty_generate([1, 2, {"a"=>3.141}, false, true, nil, 4..10])
202
+ [
203
+ 1,
204
+ 2,
205
+ {
206
+ "a": 3.141
207
+ },
208
+ false,
209
+ true,
210
+ null,
211
+ {
212
+ "json_class": "Range",
213
+ "data": [
214
+ 4,
215
+ 10,
216
+ false
217
+ ]
218
+ }
219
+ ]
220
+
221
+ There are also the methods Kernel#j for generate, and Kernel#jj for
222
+ pretty_generate output to the console, that work analogous to Core Ruby's p and
223
+ the pp library's pp methods.
224
+
225
+ The script tools/server.rb contains a small example if you want to test, how
65
226
  receiving a JSON object from a webrick server in your browser with the
66
227
  javasript prototype library (http://www.prototypejs.org) works.
67
228
 
68
- Author
69
- ======
229
+ === Speed Comparisons
230
+
231
+ I have created some benchmark results (see the benchmarks/data-p4-3Ghz
232
+ subdir of the package) for the JSON-parser to estimate the speed up in the C
233
+ extension:
234
+
235
+ Comparing times (call_time_mean):
236
+ 1 ParserBenchmarkExt#parser 900 repeats:
237
+ 553.922304770 ( real) -> 21.500x
238
+ 0.001805307
239
+ 2 ParserBenchmarkYAML#parser 1000 repeats:
240
+ 224.513358139 ( real) -> 8.714x
241
+ 0.004454078
242
+ 3 ParserBenchmarkPure#parser 1000 repeats:
243
+ 26.755020642 ( real) -> 1.038x
244
+ 0.037376163
245
+ 4 ParserBenchmarkRails#parser 1000 repeats:
246
+ 25.763381731 ( real) -> 1.000x
247
+ 0.038814780
248
+ calls/sec ( time) -> speed covers
249
+ secs/call
70
250
 
71
- Florian Frank <flori@ping.de>
251
+ In the table above 1 is JSON::Ext::Parser, 2 is YAML.load with YAML
252
+ compatbile JSON document, 3 is is JSON::Pure::Parser, and 4 is
253
+ ActiveSupport::JSON.decode. The ActiveSupport JSON-decoder converts the
254
+ input first to YAML and then uses the YAML-parser, the conversion seems to
255
+ slow it down so much that it is only as fast as the JSON::Pure::Parser!
72
256
 
73
- License
74
- =======
257
+ If you look at the benchmark data you can see that this is mostly caused by
258
+ the frequent high outliers - the median of the Rails-parser runs is still
259
+ overall smaller than the median of the JSON::Pure::Parser runs:
260
+
261
+ Comparing times (call_time_median):
262
+ 1 ParserBenchmarkExt#parser 900 repeats:
263
+ 800.592479481 ( real) -> 26.936x
264
+ 0.001249075
265
+ 2 ParserBenchmarkYAML#parser 1000 repeats:
266
+ 271.002390644 ( real) -> 9.118x
267
+ 0.003690004
268
+ 3 ParserBenchmarkRails#parser 1000 repeats:
269
+ 30.227910865 ( real) -> 1.017x
270
+ 0.033082008
271
+ 4 ParserBenchmarkPure#parser 1000 repeats:
272
+ 29.722384421 ( real) -> 1.000x
273
+ 0.033644676
274
+ calls/sec ( time) -> speed covers
275
+ secs/call
276
+
277
+ I have benchmarked the JSON-Generator as well. This generated a few more
278
+ values, because there are different modes that also influence the achieved
279
+ speed:
280
+
281
+ Comparing times (call_time_mean):
282
+ 1 GeneratorBenchmarkExt#generator_fast 1000 repeats:
283
+ 547.354332608 ( real) -> 15.090x
284
+ 0.001826970
285
+ 2 GeneratorBenchmarkExt#generator_safe 1000 repeats:
286
+ 443.968212317 ( real) -> 12.240x
287
+ 0.002252414
288
+ 3 GeneratorBenchmarkExt#generator_pretty 900 repeats:
289
+ 375.104545883 ( real) -> 10.341x
290
+ 0.002665923
291
+ 4 GeneratorBenchmarkPure#generator_fast 1000 repeats:
292
+ 49.978706968 ( real) -> 1.378x
293
+ 0.020008521
294
+ 5 GeneratorBenchmarkRails#generator 1000 repeats:
295
+ 38.531868759 ( real) -> 1.062x
296
+ 0.025952543
297
+ 6 GeneratorBenchmarkPure#generator_safe 1000 repeats:
298
+ 36.927649925 ( real) -> 1.018x 7 (>=3859)
299
+ 0.027079979
300
+ 7 GeneratorBenchmarkPure#generator_pretty 1000 repeats:
301
+ 36.272134441 ( real) -> 1.000x 6 (>=3859)
302
+ 0.027569373
303
+ calls/sec ( time) -> speed covers
304
+ secs/call
305
+
306
+ In the table above 1-3 are JSON::Ext::Generator methods. 4, 6, and 7 are
307
+ JSON::Pure::Generator methods and 5 is the Rails JSON generator. It is now a
308
+ bit faster than the generator_safe and generator_pretty methods of the pure
309
+ variant but slower than the others.
310
+
311
+ To achieve the fastest JSON document output, you can use the fast_generate
312
+ method. Beware, that this will disable the checking for circular Ruby data
313
+ structures, which may cause JSON to go into an infinite loop.
314
+
315
+ Here are the median comparisons for completeness' sake:
316
+
317
+ Comparing times (call_time_median):
318
+ 1 GeneratorBenchmarkExt#generator_fast 1000 repeats:
319
+ 708.258020939 ( real) -> 16.547x
320
+ 0.001411915
321
+ 2 GeneratorBenchmarkExt#generator_safe 1000 repeats:
322
+ 569.105020353 ( real) -> 13.296x
323
+ 0.001757145
324
+ 3 GeneratorBenchmarkExt#generator_pretty 900 repeats:
325
+ 482.825371244 ( real) -> 11.280x
326
+ 0.002071142
327
+ 4 GeneratorBenchmarkPure#generator_fast 1000 repeats:
328
+ 62.717626652 ( real) -> 1.465x
329
+ 0.015944481
330
+ 5 GeneratorBenchmarkRails#generator 1000 repeats:
331
+ 43.965681162 ( real) -> 1.027x
332
+ 0.022745013
333
+ 6 GeneratorBenchmarkPure#generator_safe 1000 repeats:
334
+ 43.929073409 ( real) -> 1.026x 7 (>=3859)
335
+ 0.022763968
336
+ 7 GeneratorBenchmarkPure#generator_pretty 1000 repeats:
337
+ 42.802514491 ( real) -> 1.000x 6 (>=3859)
338
+ 0.023363113
339
+ calls/sec ( time) -> speed covers
340
+ secs/call
341
+
342
+ === Author
343
+
344
+ Florian Frank <mailto:flori@ping.de>
345
+
346
+ === License
75
347
 
76
348
  Ruby License, see the COPYING file included in the source distribution. The
77
349
  Ruby License includes the GNU General Public License (GPL), Version 2, so see
78
350
  the file GPL as well.
351
+
352
+ === Download
353
+
354
+ The latest version of this library can be downloaded at
355
+
356
+ * http://rubyforge.org/frs?group_id=953
357
+
358
+ Online Documentation should be located at
359
+
360
+ * http://json.rubyforge.org
data/Rakefile CHANGED
@@ -1,8 +1,14 @@
1
1
  begin
2
2
  require 'rake/gempackagetask'
3
+ rescue LoadError
4
+ end
5
+
6
+ begin
3
7
  require 'rake/extensiontask'
4
8
  rescue LoadError
9
+ puts "WARNING: rake-compiler is not installed. You will not be able to build the json gem until you install it."
5
10
  end
11
+
6
12
  require 'rake/clean'
7
13
  CLOBBER.include Dir['benchmarks/data/*.{dat,log}']
8
14
 
@@ -12,7 +18,7 @@ include Config
12
18
  MAKE = ENV['MAKE'] || %w[gmake make].find { |c| system(c, '-v') }
13
19
  PKG_NAME = 'json'
14
20
  PKG_VERSION = File.read('VERSION').chomp
15
- PKG_FILES = FileList["**/*"].exclude(/CVS|pkg|tmp|coverage|Makefile/).exclude(/\.(so|bundle|o|#{CONFIG['DLEXT']})$/)
21
+ PKG_FILES = FileList["**/*"].exclude(/CVS|pkg|tmp|coverage|Makefile|\.nfs\./).exclude(/\.(so|bundle|o|#{CONFIG['DLEXT']})$/)
16
22
  EXT_ROOT_DIR = 'ext/json/ext'
17
23
  EXT_PARSER_DIR = "#{EXT_ROOT_DIR}/parser"
18
24
  EXT_PARSER_DL = "#{EXT_ROOT_DIR}/parser.#{CONFIG['DLEXT']}"
@@ -28,9 +34,19 @@ CLEAN.include FileList['diagrams/*.*'], 'doc', 'coverage', 'tmp',
28
34
  FileList["ext/**/{Makefile,mkmf.log}"],
29
35
  FileList["{ext,lib}/**/*.{so,bundle,#{CONFIG['DLEXT']},o,obj,pdb,lib,manifest,exp,def}"]
30
36
 
37
+ def myruby(*args, &block)
38
+ @myruby ||= File.join(CONFIG['bindir'], CONFIG['ruby_install_name'])
39
+ options = (Hash === args.last) ? args.pop : {}
40
+ if args.length > 1 then
41
+ sh(*([@myruby] + args + [options]), &block)
42
+ else
43
+ sh("#{@myruby} #{args.first}", options, &block)
44
+ end
45
+ end
46
+
31
47
  desc "Installing library (pure)"
32
48
  task :install_pure => :version do
33
- ruby 'install.rb'
49
+ myruby 'install.rb'
34
50
  end
35
51
 
36
52
  task :install_ext_really do
@@ -48,23 +64,27 @@ desc "Installing library (extension)"
48
64
  task :install_ext => [ :compile_ext, :install_pure, :install_ext_really ]
49
65
 
50
66
  desc "Installing library (extension)"
51
- task :install => :install_ext
67
+ if RUBY_PLATFORM =~ /java/
68
+ task :install => :install_pure
69
+ else
70
+ task :install => :install_ext
71
+ end
52
72
 
53
73
  desc "Compiling extension"
54
74
  task :compile_ext => [ EXT_PARSER_DL, EXT_GENERATOR_DL ]
55
75
 
56
76
  file EXT_PARSER_DL => EXT_PARSER_SRC do
57
77
  cd EXT_PARSER_DIR do
58
- ruby 'extconf.rb'
59
- system MAKE
78
+ myruby 'extconf.rb'
79
+ sh MAKE
60
80
  end
61
81
  cp "#{EXT_PARSER_DIR}/parser.#{CONFIG['DLEXT']}", EXT_ROOT_DIR
62
82
  end
63
83
 
64
84
  file EXT_GENERATOR_DL => EXT_GENERATOR_SRC do
65
85
  cd EXT_GENERATOR_DIR do
66
- ruby 'extconf.rb'
67
- system MAKE
86
+ myruby 'extconf.rb'
87
+ sh MAKE
68
88
  end
69
89
  cp "#{EXT_GENERATOR_DIR}/generator.#{CONFIG['DLEXT']}", EXT_ROOT_DIR
70
90
  end
@@ -79,9 +99,9 @@ end
79
99
  file EXT_PARSER_SRC => RAGEL_PATH do
80
100
  cd EXT_PARSER_DIR do
81
101
  if RAGEL_CODEGEN == 'ragel'
82
- system "ragel parser.rl -G2 -o parser.c"
102
+ sh "ragel parser.rl -G2 -o parser.c"
83
103
  else
84
- system "ragel -x parser.rl | #{RAGEL_CODEGEN} -G2"
104
+ sh "ragel -x parser.rl | #{RAGEL_CODEGEN} -G2"
85
105
  end
86
106
  end
87
107
  end
@@ -91,11 +111,11 @@ task :ragel_dot_ps do
91
111
  root = 'diagrams'
92
112
  specs = []
93
113
  File.new(RAGEL_PATH).grep(/^\s*machine\s*(\S+);\s*$/) { specs << $1 }
94
- for s in specs
114
+ for s in specs
95
115
  if RAGEL_DOTGEN == 'ragel'
96
- system "ragel #{RAGEL_PATH} -S#{s} -p -V | dot -Tps -o#{root}/#{s}.ps"
116
+ sh "ragel #{RAGEL_PATH} -S#{s} -p -V | dot -Tps -o#{root}/#{s}.ps"
97
117
  else
98
- system "ragel -x #{RAGEL_PATH} -S#{s} | #{RAGEL_DOTGEN} -p|dot -Tps -o#{root}/#{s}.ps"
118
+ sh "ragel -x #{RAGEL_PATH} -S#{s} | #{RAGEL_DOTGEN} -p|dot -Tps -o#{root}/#{s}.ps"
99
119
  end
100
120
  end
101
121
  end
@@ -105,11 +125,11 @@ task :ragel_dot_png do
105
125
  root = 'diagrams'
106
126
  specs = []
107
127
  File.new(RAGEL_PATH).grep(/^\s*machine\s*(\S+);\s*$/) { specs << $1 }
108
- for s in specs
128
+ for s in specs
109
129
  if RAGEL_DOTGEN == 'ragel'
110
- system "ragel #{RAGEL_PATH} -S#{s} -p -V | dot -Tpng -o#{root}/#{s}.png"
130
+ sh "ragel #{RAGEL_PATH} -S#{s} -p -V | dot -Tpng -o#{root}/#{s}.png"
111
131
  else
112
- system "ragel -x #{RAGEL_PATH} -S#{s} | #{RAGEL_DOTGEN} -p|dot -Tpng -o#{root}/#{s}.png"
132
+ sh "ragel -x #{RAGEL_PATH} -S#{s} | #{RAGEL_DOTGEN} -p|dot -Tpng -o#{root}/#{s}.png"
113
133
  end
114
134
  end
115
135
  end
@@ -121,14 +141,14 @@ desc "Testing library (pure ruby)"
121
141
  task :test_pure => :clean do
122
142
  ENV['JSON'] = 'pure'
123
143
  ENV['RUBYOPT'] = "-Iext:lib #{ENV['RUBYOPT']}"
124
- system "testrb #{Dir['tests/*.rb'] * ' '}"
144
+ myruby "-S testrb #{Dir['./tests/*.rb'] * ' '}"
125
145
  end
126
146
 
127
147
  desc "Testing library (extension)"
128
148
  task :test_ext => :compile_ext do
129
149
  ENV['JSON'] = 'ext'
130
150
  ENV['RUBYOPT'] = "-Iext:lib #{ENV['RUBYOPT']}"
131
- system "testrb #{Dir['tests/*.rb'] * ' '}"
151
+ myruby "-S testrb #{Dir['./tests/*.rb'] * ' '}"
132
152
  end
133
153
 
134
154
  desc "Testing library (pure ruby and extension)"
@@ -137,13 +157,13 @@ task :test => [ :test_pure, :test_ext ]
137
157
  desc "Benchmarking parser"
138
158
  task :benchmark_parser do
139
159
  ENV['RUBYOPT'] = "-Ilib:ext #{ENV['RUBYOPT']}"
140
- ruby 'benchmarks/parser_benchmark.rb'
160
+ myruby 'benchmarks/parser_benchmark.rb'
141
161
  end
142
162
 
143
163
  desc "Benchmarking generator"
144
164
  task :benchmark_generator do
145
165
  ENV['RUBYOPT'] = "-Ilib:ext #{ENV['RUBYOPT']}"
146
- ruby 'benchmarks/generator_benchmark.rb'
166
+ myruby 'benchmarks/generator_benchmark.rb'
147
167
  end
148
168
 
149
169
  desc "Benchmarking library"
@@ -151,7 +171,7 @@ task :benchmark => [ :benchmark_parser, :benchmark_generator ]
151
171
 
152
172
  desc "Create RDOC documentation"
153
173
  task :doc => [ :version, EXT_PARSER_SRC ] do
154
- system "rdoc -o doc -m doc-main.txt doc-main.txt lib/json.rb #{FileList['lib/json/**/*.rb']} #{EXT_PARSER_SRC} #{EXT_GENERATOR_SRC}"
174
+ sh "rdoc -o doc -m README README lib/json.rb #{FileList['lib/json/**/*.rb']} #{EXT_PARSER_SRC} #{EXT_GENERATOR_SRC}"
155
175
  end
156
176
 
157
177
  if defined?(Gem) and defined?(Rake::GemPackageTask) and defined?(Rake::ExtensionTask)
@@ -170,9 +190,9 @@ if defined?(Gem) and defined?(Rake::GemPackageTask) and defined?(Rake::Extension
170
190
  s.default_executable = "edit_json.rb"
171
191
 
172
192
  s.has_rdoc = true
173
- s.extra_rdoc_files << 'doc-main.txt'
193
+ s.extra_rdoc_files << 'README'
174
194
  s.rdoc_options <<
175
- '--title' << 'JSON -- A JSON implemention' << '--main' << 'doc-main.txt'
195
+ '--title' << 'JSON -- A JSON implemention' << '--main' << 'README'
176
196
  s.test_files.concat Dir['tests/*.rb']
177
197
 
178
198
  s.author = "Florian Frank"
@@ -183,7 +203,7 @@ if defined?(Gem) and defined?(Rake::GemPackageTask) and defined?(Rake::Extension
183
203
 
184
204
  Rake::GemPackageTask.new(spec_pure) do |pkg|
185
205
  pkg.need_tar = true
186
- pkg.package_files += PKG_FILES
206
+ pkg.package_files = PKG_FILES
187
207
  end
188
208
 
189
209
  spec_ext = Gem::Specification.new do |s|
@@ -205,9 +225,9 @@ if defined?(Gem) and defined?(Rake::GemPackageTask) and defined?(Rake::Extension
205
225
  s.default_executable = "edit_json.rb"
206
226
 
207
227
  s.has_rdoc = true
208
- s.extra_rdoc_files << 'doc-main.txt'
228
+ s.extra_rdoc_files << 'README'
209
229
  s.rdoc_options <<
210
- '--title' << 'JSON -- A JSON implemention' << '--main' << 'doc-main.txt'
230
+ '--title' << 'JSON -- A JSON implemention' << '--main' << 'README'
211
231
  s.test_files.concat Dir['tests/*.rb']
212
232
 
213
233
  s.author = "Florian Frank"
@@ -229,7 +249,7 @@ if defined?(Gem) and defined?(Rake::GemPackageTask) and defined?(Rake::Extension
229
249
  ext.ext_dir = 'ext/json/ext/parser'
230
250
  ext.lib_dir = 'lib/json/ext'
231
251
  end
232
-
252
+
233
253
  Rake::ExtensionTask.new do |ext|
234
254
  ext.name = 'generator'
235
255
  ext.gem_spec = spec_ext
@@ -259,8 +279,8 @@ end
259
279
 
260
280
  desc "Build all gems and archives for a new release."
261
281
  task :release => [ :clean, :version, :cross, :native, :gem ] do
262
- system "#$0 clean native gem"
263
- system "#$0 clean package"
282
+ sh "#$0 clean native gem"
283
+ sh "#$0 clean package"
264
284
  end
265
285
 
266
286
  desc "Compile in the the source directory"