rack-link_headers 2.3.0 → 2.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -6
- data/lib/rack/link_headers/version.rb +3 -3
- data/rack-link-headers.gemspec +7 -4
- data/test/helper_test.rb +7 -4
- data/vendor/bundle/ruby/3.3.0/bundler/gems/rubocop-config-943facea9d8f/LICENSE +21 -0
- data/vendor/bundle/ruby/3.3.0/bundler/gems/rubocop-config-943facea9d8f/README.md +23 -0
- data/vendor/bundle/ruby/3.3.0/bundler/gems/rubocop-config-943facea9d8f/rubocop-config.gemspec +31 -0
- data/vendor/bundle/ruby/3.3.0/gems/ast-2.4.2/LICENSE.MIT +20 -0
- data/vendor/bundle/ruby/3.3.0/gems/ast-2.4.2/README.YARD.md +12 -0
- data/vendor/bundle/ruby/3.3.0/gems/json-2.7.2/LICENSE +56 -0
- data/vendor/bundle/ruby/3.3.0/gems/json-2.7.2/README.md +416 -0
- data/vendor/bundle/ruby/3.3.0/gems/json-2.7.2/json.gemspec +68 -0
- data/vendor/bundle/ruby/3.3.0/gems/language_server-protocol-3.17.0.3/LICENSE.txt +21 -0
- data/vendor/bundle/ruby/3.3.0/gems/language_server-protocol-3.17.0.3/README.md +88 -0
- data/vendor/bundle/ruby/3.3.0/gems/minitest-5.25.1/README.rdoc +835 -0
- data/vendor/bundle/ruby/3.3.0/gems/parallel-1.26.3/MIT-LICENSE.txt +20 -0
- data/vendor/bundle/ruby/3.3.0/gems/parser-3.3.5.0/LICENSE.txt +25 -0
- data/vendor/bundle/ruby/3.3.0/gems/parser-3.3.5.0/parser.gemspec +43 -0
- data/vendor/bundle/ruby/3.3.0/gems/racc-1.8.1/README.ja.rdoc +58 -0
- data/vendor/bundle/ruby/3.3.0/gems/racc-1.8.1/README.rdoc +60 -0
- data/vendor/bundle/ruby/3.3.0/gems/rack-3.1.7/CHANGELOG.md +994 -0
- data/vendor/bundle/ruby/3.3.0/gems/rack-3.1.7/MIT-LICENSE +20 -0
- data/vendor/bundle/ruby/3.3.0/gems/rack-3.1.7/README.md +328 -0
- data/vendor/bundle/ruby/3.3.0/gems/rainbow-3.1.1/LICENSE +20 -0
- data/vendor/bundle/ruby/3.3.0/gems/rainbow-3.1.1/README.markdown +227 -0
- data/vendor/bundle/ruby/3.3.0/gems/rake-13.2.1/MIT-LICENSE +21 -0
- data/vendor/bundle/ruby/3.3.0/gems/rake-13.2.1/README.rdoc +155 -0
- data/vendor/bundle/ruby/3.3.0/gems/rake-13.2.1/rake.gemspec +101 -0
- data/vendor/bundle/ruby/3.3.0/gems/rake-release-1.3.0/LICENSE +21 -0
- data/vendor/bundle/ruby/3.3.0/gems/rake-release-1.3.0/README.md +107 -0
- data/vendor/bundle/ruby/3.3.0/gems/rake-release-1.3.0/rake-release.gemspec +23 -0
- data/vendor/bundle/ruby/3.3.0/gems/regexp_parser-2.9.2/LICENSE +22 -0
- data/vendor/bundle/ruby/3.3.0/gems/regexp_parser-2.9.2/regexp_parser.gemspec +34 -0
- data/vendor/bundle/ruby/3.3.0/gems/rexml-3.3.7/LICENSE.txt +22 -0
- data/vendor/bundle/ruby/3.3.0/gems/rexml-3.3.7/README.md +57 -0
- data/vendor/bundle/ruby/3.3.0/gems/rubocop-1.65.1/LICENSE.txt +20 -0
- data/vendor/bundle/ruby/3.3.0/gems/rubocop-1.65.1/README.md +251 -0
- data/vendor/bundle/ruby/3.3.0/gems/rubocop-ast-1.32.3/LICENSE.txt +20 -0
- data/vendor/bundle/ruby/3.3.0/gems/rubocop-ast-1.32.3/README.md +56 -0
- data/vendor/bundle/ruby/3.3.0/gems/rubocop-capybara-2.21.0/CHANGELOG.md +85 -0
- data/vendor/bundle/ruby/3.3.0/gems/rubocop-capybara-2.21.0/MIT-LICENSE.md +21 -0
- data/vendor/bundle/ruby/3.3.0/gems/rubocop-capybara-2.21.0/README.md +88 -0
- data/vendor/bundle/ruby/3.3.0/gems/rubocop-factory_bot-2.26.1/CHANGELOG.md +116 -0
- data/vendor/bundle/ruby/3.3.0/gems/rubocop-factory_bot-2.26.1/MIT-LICENSE.md +21 -0
- data/vendor/bundle/ruby/3.3.0/gems/rubocop-factory_bot-2.26.1/README.md +88 -0
- data/vendor/bundle/ruby/3.3.0/gems/rubocop-performance-1.21.1/LICENSE.txt +20 -0
- data/vendor/bundle/ruby/3.3.0/gems/rubocop-performance-1.21.1/README.md +97 -0
- data/vendor/bundle/ruby/3.3.0/gems/rubocop-rspec-3.0.5/CHANGELOG.md +1034 -0
- data/vendor/bundle/ruby/3.3.0/gems/rubocop-rspec-3.0.5/MIT-LICENSE.md +21 -0
- data/vendor/bundle/ruby/3.3.0/gems/rubocop-rspec-3.0.5/README.md +109 -0
- data/vendor/bundle/ruby/3.3.0/gems/rubocop-rspec_rails-2.30.0/CHANGELOG.md +84 -0
- data/vendor/bundle/ruby/3.3.0/gems/rubocop-rspec_rails-2.30.0/MIT-LICENSE.md +21 -0
- data/vendor/bundle/ruby/3.3.0/gems/rubocop-rspec_rails-2.30.0/README.md +90 -0
- data/vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/LICENSE.txt +19 -0
- data/vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/README.md +131 -0
- data/vendor/bundle/ruby/3.3.0/gems/unicode-display_width-2.6.0/CHANGELOG.md +200 -0
- data/vendor/bundle/ruby/3.3.0/gems/unicode-display_width-2.6.0/MIT-LICENSE.txt +22 -0
- data/vendor/bundle/ruby/3.3.0/gems/unicode-display_width-2.6.0/README.md +171 -0
- data/vendor/bundle/ruby/3.3.0/specifications/ast-2.4.2.gemspec +30 -0
- data/vendor/bundle/ruby/3.3.0/specifications/json-2.7.2.gemspec +0 -0
- data/vendor/bundle/ruby/3.3.0/specifications/language_server-protocol-3.17.0.3.gemspec +31 -0
- data/vendor/bundle/ruby/3.3.0/specifications/minitest-5.25.1.gemspec +31 -0
- data/vendor/bundle/ruby/3.3.0/specifications/parallel-1.26.3.gemspec +21 -0
- data/vendor/bundle/ruby/3.3.0/specifications/parser-3.3.5.0.gemspec +37 -0
- data/vendor/bundle/ruby/3.3.0/specifications/racc-1.8.1.gemspec +28 -0
- data/vendor/bundle/ruby/3.3.0/specifications/rack-3.1.7.gemspec +31 -0
- data/vendor/bundle/ruby/3.3.0/specifications/rainbow-3.1.1.gemspec +25 -0
- data/vendor/bundle/ruby/3.3.0/specifications/rake-13.2.1.gemspec +26 -0
- data/vendor/bundle/ruby/3.3.0/specifications/rake-release-1.3.0.gemspec +26 -0
- data/vendor/bundle/ruby/3.3.0/specifications/regexp_parser-2.9.2.gemspec +22 -0
- data/vendor/bundle/ruby/3.3.0/specifications/rexml-3.3.7.gemspec +25 -0
- data/vendor/bundle/ruby/3.3.0/specifications/rubocop-1.65.1.gemspec +39 -0
- data/vendor/bundle/ruby/3.3.0/specifications/rubocop-ast-1.32.3.gemspec +28 -0
- data/vendor/bundle/ruby/3.3.0/specifications/rubocop-capybara-2.21.0.gemspec +27 -0
- data/vendor/bundle/ruby/3.3.0/specifications/rubocop-factory_bot-2.26.1.gemspec +27 -0
- data/vendor/bundle/ruby/3.3.0/specifications/rubocop-performance-1.21.1.gemspec +29 -0
- data/vendor/bundle/ruby/3.3.0/specifications/rubocop-rspec-3.0.5.gemspec +28 -0
- data/vendor/bundle/ruby/3.3.0/specifications/rubocop-rspec_rails-2.30.0.gemspec +28 -0
- data/vendor/bundle/ruby/3.3.0/specifications/ruby-progressbar-1.13.0.gemspec +29 -0
- data/vendor/bundle/ruby/3.3.0/specifications/unicode-display_width-2.6.0.gemspec +29 -0
- metadata +84 -8
@@ -0,0 +1,416 @@
|
|
1
|
+
# JSON implementation for Ruby
|
2
|
+
|
3
|
+
[![CI](https://github.com/flori/json/actions/workflows/ci.yml/badge.svg)](https://github.com/flori/json/actions/workflows/ci.yml)
|
4
|
+
|
5
|
+
## Description
|
6
|
+
|
7
|
+
This is a implementation of the JSON specification according to RFC 7159
|
8
|
+
http://www.ietf.org/rfc/rfc7159.txt . Starting from version 1.0.0 on there
|
9
|
+
will be two variants available:
|
10
|
+
|
11
|
+
* A pure ruby variant, that relies on the iconv and the stringscan
|
12
|
+
extensions, which are both part of the ruby standard library.
|
13
|
+
* The quite a bit faster native extension variant, which is in parts
|
14
|
+
implemented in C or Java and comes with its own unicode conversion
|
15
|
+
functions and a parser generated by the [Ragel] state machine compiler.
|
16
|
+
|
17
|
+
Both variants of the JSON generator generate UTF-8 character sequences by
|
18
|
+
default. If an :ascii\_only option with a true value is given, they escape all
|
19
|
+
non-ASCII and control characters with \uXXXX escape sequences, and support
|
20
|
+
UTF-16 surrogate pairs in order to be able to generate the whole range of
|
21
|
+
unicode code points.
|
22
|
+
|
23
|
+
All strings, that are to be encoded as JSON strings, should be UTF-8 byte
|
24
|
+
sequences on the Ruby side. To encode raw binary strings, that aren't UTF-8
|
25
|
+
encoded, please use the to\_json\_raw\_object method of String (which produces
|
26
|
+
an object, that contains a byte array) and decode the result on the receiving
|
27
|
+
endpoint.
|
28
|
+
|
29
|
+
## Installation
|
30
|
+
|
31
|
+
It's recommended to use the extension variant of JSON, because it's faster than
|
32
|
+
the pure ruby variant. If you cannot build it on your system, you can settle
|
33
|
+
for the latter.
|
34
|
+
|
35
|
+
Just type into the command line as root:
|
36
|
+
|
37
|
+
```
|
38
|
+
# rake install
|
39
|
+
```
|
40
|
+
|
41
|
+
The above command will build the extensions and install them on your system.
|
42
|
+
|
43
|
+
```
|
44
|
+
# rake install_pure
|
45
|
+
```
|
46
|
+
|
47
|
+
or
|
48
|
+
|
49
|
+
```
|
50
|
+
# ruby install.rb
|
51
|
+
```
|
52
|
+
|
53
|
+
will just install the pure ruby implementation of JSON.
|
54
|
+
|
55
|
+
If you use Rubygems you can type
|
56
|
+
|
57
|
+
```
|
58
|
+
# gem install json
|
59
|
+
```
|
60
|
+
|
61
|
+
instead, to install the newest JSON version.
|
62
|
+
|
63
|
+
There is also a pure ruby json only variant of the gem, that can be installed
|
64
|
+
with:
|
65
|
+
|
66
|
+
```
|
67
|
+
# gem install json_pure
|
68
|
+
```
|
69
|
+
|
70
|
+
## Compiling the extensions yourself
|
71
|
+
|
72
|
+
If you want to create the `parser.c` file from its `parser.rl` file or draw nice
|
73
|
+
graphviz images of the state machines, you need [Ragel].
|
74
|
+
|
75
|
+
## Usage
|
76
|
+
|
77
|
+
To use JSON you can
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
require 'json'
|
81
|
+
```
|
82
|
+
|
83
|
+
to load the installed variant (either the extension `'json'` or the pure
|
84
|
+
variant `'json_pure'`). If you have installed the extension variant, you can
|
85
|
+
pick either the extension variant or the pure variant by typing
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
require 'json/ext'
|
89
|
+
```
|
90
|
+
|
91
|
+
or
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
require 'json/pure'
|
95
|
+
```
|
96
|
+
|
97
|
+
Now you can parse a JSON document into a ruby data structure by calling
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
JSON.parse(document)
|
101
|
+
```
|
102
|
+
|
103
|
+
If you want to generate a JSON document from a ruby data structure call
|
104
|
+
```ruby
|
105
|
+
JSON.generate(data)
|
106
|
+
```
|
107
|
+
|
108
|
+
You can also use the `pretty_generate` method (which formats the output more
|
109
|
+
verbosely and nicely) or `fast_generate` (which doesn't do any of the security
|
110
|
+
checks generate performs, e. g. nesting deepness checks).
|
111
|
+
|
112
|
+
There are also the JSON and JSON[] methods which use parse on a String or
|
113
|
+
generate a JSON document from an array or hash:
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
document = JSON 'test' => 23 # => "{\"test\":23}"
|
117
|
+
document = JSON['test' => 23] # => "{\"test\":23}"
|
118
|
+
```
|
119
|
+
|
120
|
+
and
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
data = JSON '{"test":23}' # => {"test"=>23}
|
124
|
+
data = JSON['{"test":23}'] # => {"test"=>23}
|
125
|
+
```
|
126
|
+
|
127
|
+
You can choose to load a set of common additions to ruby core's objects if
|
128
|
+
you
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
require 'json/add/core'
|
132
|
+
```
|
133
|
+
|
134
|
+
After requiring this you can, e. g., serialise/deserialise Ruby ranges:
|
135
|
+
|
136
|
+
```ruby
|
137
|
+
JSON JSON(1..10) # => 1..10
|
138
|
+
```
|
139
|
+
|
140
|
+
To find out how to add JSON support to other or your own classes, read the
|
141
|
+
section "More Examples" below.
|
142
|
+
|
143
|
+
## Serializing exceptions
|
144
|
+
|
145
|
+
The JSON module doesn't extend `Exception` by default. If you convert an `Exception`
|
146
|
+
object to JSON, it will by default only include the exception message.
|
147
|
+
|
148
|
+
To include the full details, you must either load the `json/add/core` mentioned
|
149
|
+
above, or specifically load the exception addition:
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
require 'json/add/exception'
|
153
|
+
```
|
154
|
+
|
155
|
+
## More Examples
|
156
|
+
|
157
|
+
To create a JSON document from a ruby data structure, you can call
|
158
|
+
`JSON.generate` like that:
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
|
162
|
+
# => "[1,2,{\"a\":3.141},false,true,null,\"4..10\"]"
|
163
|
+
```
|
164
|
+
|
165
|
+
To get back a ruby data structure from a JSON document, you have to call
|
166
|
+
JSON.parse on it:
|
167
|
+
|
168
|
+
```ruby
|
169
|
+
JSON.parse json
|
170
|
+
# => [1, 2, {"a"=>3.141}, false, true, nil, "4..10"]
|
171
|
+
```
|
172
|
+
|
173
|
+
Note, that the range from the original data structure is a simple
|
174
|
+
string now. The reason for this is, that JSON doesn't support ranges
|
175
|
+
or arbitrary classes. In this case the json library falls back to call
|
176
|
+
`Object#to_json`, which is the same as `#to_s.to_json`.
|
177
|
+
|
178
|
+
It's possible to add JSON support serialization to arbitrary classes by
|
179
|
+
simply implementing a more specialized version of the `#to_json method`, that
|
180
|
+
should return a JSON object (a hash converted to JSON with `#to_json`) like
|
181
|
+
this (don't forget the `*a` for all the arguments):
|
182
|
+
|
183
|
+
```ruby
|
184
|
+
class Range
|
185
|
+
def to_json(*a)
|
186
|
+
{
|
187
|
+
'json_class' => self.class.name, # = 'Range'
|
188
|
+
'data' => [ first, last, exclude_end? ]
|
189
|
+
}.to_json(*a)
|
190
|
+
end
|
191
|
+
end
|
192
|
+
```
|
193
|
+
|
194
|
+
The hash key `json_class` is the class, that will be asked to deserialise the
|
195
|
+
JSON representation later. In this case it's `Range`, but any namespace of
|
196
|
+
the form `A::B` or `::A::B` will do. All other keys are arbitrary and can be
|
197
|
+
used to store the necessary data to configure the object to be deserialised.
|
198
|
+
|
199
|
+
If the key `json_class` is found in a JSON object, the JSON parser checks
|
200
|
+
if the given class responds to the `json_create` class method. If so, it is
|
201
|
+
called with the JSON object converted to a Ruby hash. So a range can
|
202
|
+
be deserialised by implementing `Range.json_create` like this:
|
203
|
+
|
204
|
+
```ruby
|
205
|
+
class Range
|
206
|
+
def self.json_create(o)
|
207
|
+
new(*o['data'])
|
208
|
+
end
|
209
|
+
end
|
210
|
+
```
|
211
|
+
|
212
|
+
Now it possible to serialise/deserialise ranges as well:
|
213
|
+
|
214
|
+
```ruby
|
215
|
+
json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
|
216
|
+
# => "[1,2,{\"a\":3.141},false,true,null,{\"json_class\":\"Range\",\"data\":[4,10,false]}]"
|
217
|
+
JSON.parse json
|
218
|
+
# => [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
|
219
|
+
json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
|
220
|
+
# => "[1,2,{\"a\":3.141},false,true,null,{\"json_class\":\"Range\",\"data\":[4,10,false]}]"
|
221
|
+
JSON.parse json, :create_additions => true
|
222
|
+
# => [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
|
223
|
+
```
|
224
|
+
|
225
|
+
`JSON.generate` always creates the shortest possible string representation of a
|
226
|
+
ruby data structure in one line. This is good for data storage or network
|
227
|
+
protocols, but not so good for humans to read. Fortunately there's also
|
228
|
+
`JSON.pretty_generate` (or `JSON.pretty_generate`) that creates a more readable
|
229
|
+
output:
|
230
|
+
|
231
|
+
```ruby
|
232
|
+
puts JSON.pretty_generate([1, 2, {"a"=>3.141}, false, true, nil, 4..10])
|
233
|
+
[
|
234
|
+
1,
|
235
|
+
2,
|
236
|
+
{
|
237
|
+
"a": 3.141
|
238
|
+
},
|
239
|
+
false,
|
240
|
+
true,
|
241
|
+
null,
|
242
|
+
{
|
243
|
+
"json_class": "Range",
|
244
|
+
"data": [
|
245
|
+
4,
|
246
|
+
10,
|
247
|
+
false
|
248
|
+
]
|
249
|
+
}
|
250
|
+
]
|
251
|
+
```
|
252
|
+
|
253
|
+
There are also the methods `Kernel#j` for generate, and `Kernel#jj` for
|
254
|
+
`pretty_generate` output to the console, that work analogous to Core Ruby's `p` and
|
255
|
+
the `pp` library's `pp` methods.
|
256
|
+
|
257
|
+
The script `tools/server.rb` contains a small example if you want to test, how
|
258
|
+
receiving a JSON object from a webrick server in your browser with the
|
259
|
+
JavaScript prototype library http://www.prototypejs.org works.
|
260
|
+
|
261
|
+
## Speed Comparisons
|
262
|
+
|
263
|
+
I have created some benchmark results (see the benchmarks/data-p4-3Ghz
|
264
|
+
subdir of the package) for the JSON-parser to estimate the speed up in the C
|
265
|
+
extension:
|
266
|
+
|
267
|
+
```
|
268
|
+
Comparing times (call_time_mean):
|
269
|
+
1 ParserBenchmarkExt#parser 900 repeats:
|
270
|
+
553.922304770 ( real) -> 21.500x
|
271
|
+
0.001805307
|
272
|
+
2 ParserBenchmarkYAML#parser 1000 repeats:
|
273
|
+
224.513358139 ( real) -> 8.714x
|
274
|
+
0.004454078
|
275
|
+
3 ParserBenchmarkPure#parser 1000 repeats:
|
276
|
+
26.755020642 ( real) -> 1.038x
|
277
|
+
0.037376163
|
278
|
+
4 ParserBenchmarkRails#parser 1000 repeats:
|
279
|
+
25.763381731 ( real) -> 1.000x
|
280
|
+
0.038814780
|
281
|
+
calls/sec ( time) -> speed covers
|
282
|
+
secs/call
|
283
|
+
```
|
284
|
+
|
285
|
+
In the table above 1 is `JSON::Ext::Parser`, 2 is `YAML.load` with YAML
|
286
|
+
compatible JSON document, 3 is is `JSON::Pure::Parser`, and 4 is
|
287
|
+
`ActiveSupport::JSON.decode`. The ActiveSupport JSON-decoder converts the
|
288
|
+
input first to YAML and then uses the YAML-parser, the conversion seems to
|
289
|
+
slow it down so much that it is only as fast as the `JSON::Pure::Parser`!
|
290
|
+
|
291
|
+
If you look at the benchmark data you can see that this is mostly caused by
|
292
|
+
the frequent high outliers - the median of the Rails-parser runs is still
|
293
|
+
overall smaller than the median of the `JSON::Pure::Parser` runs:
|
294
|
+
|
295
|
+
```
|
296
|
+
Comparing times (call_time_median):
|
297
|
+
1 ParserBenchmarkExt#parser 900 repeats:
|
298
|
+
800.592479481 ( real) -> 26.936x
|
299
|
+
0.001249075
|
300
|
+
2 ParserBenchmarkYAML#parser 1000 repeats:
|
301
|
+
271.002390644 ( real) -> 9.118x
|
302
|
+
0.003690004
|
303
|
+
3 ParserBenchmarkRails#parser 1000 repeats:
|
304
|
+
30.227910865 ( real) -> 1.017x
|
305
|
+
0.033082008
|
306
|
+
4 ParserBenchmarkPure#parser 1000 repeats:
|
307
|
+
29.722384421 ( real) -> 1.000x
|
308
|
+
0.033644676
|
309
|
+
calls/sec ( time) -> speed covers
|
310
|
+
secs/call
|
311
|
+
```
|
312
|
+
|
313
|
+
I have benchmarked the `JSON-Generator` as well. This generated a few more
|
314
|
+
values, because there are different modes that also influence the achieved
|
315
|
+
speed:
|
316
|
+
|
317
|
+
```
|
318
|
+
Comparing times (call_time_mean):
|
319
|
+
1 GeneratorBenchmarkExt#generator_fast 1000 repeats:
|
320
|
+
547.354332608 ( real) -> 15.090x
|
321
|
+
0.001826970
|
322
|
+
2 GeneratorBenchmarkExt#generator_safe 1000 repeats:
|
323
|
+
443.968212317 ( real) -> 12.240x
|
324
|
+
0.002252414
|
325
|
+
3 GeneratorBenchmarkExt#generator_pretty 900 repeats:
|
326
|
+
375.104545883 ( real) -> 10.341x
|
327
|
+
0.002665923
|
328
|
+
4 GeneratorBenchmarkPure#generator_fast 1000 repeats:
|
329
|
+
49.978706968 ( real) -> 1.378x
|
330
|
+
0.020008521
|
331
|
+
5 GeneratorBenchmarkRails#generator 1000 repeats:
|
332
|
+
38.531868759 ( real) -> 1.062x
|
333
|
+
0.025952543
|
334
|
+
6 GeneratorBenchmarkPure#generator_safe 1000 repeats:
|
335
|
+
36.927649925 ( real) -> 1.018x 7 (>=3859)
|
336
|
+
0.027079979
|
337
|
+
7 GeneratorBenchmarkPure#generator_pretty 1000 repeats:
|
338
|
+
36.272134441 ( real) -> 1.000x 6 (>=3859)
|
339
|
+
0.027569373
|
340
|
+
calls/sec ( time) -> speed covers
|
341
|
+
secs/call
|
342
|
+
```
|
343
|
+
|
344
|
+
In the table above 1-3 are `JSON::Ext::Generator` methods. 4, 6, and 7 are
|
345
|
+
`JSON::Pure::Generator` methods and 5 is the Rails JSON generator. It is now a
|
346
|
+
bit faster than the `generator_safe` and `generator_pretty` methods of the pure
|
347
|
+
variant but slower than the others.
|
348
|
+
|
349
|
+
To achieve the fastest JSON document output, you can use the `fast_generate`
|
350
|
+
method. Beware, that this will disable the checking for circular Ruby data
|
351
|
+
structures, which may cause JSON to go into an infinite loop.
|
352
|
+
|
353
|
+
Here are the median comparisons for completeness' sake:
|
354
|
+
|
355
|
+
```
|
356
|
+
Comparing times (call_time_median):
|
357
|
+
1 GeneratorBenchmarkExt#generator_fast 1000 repeats:
|
358
|
+
708.258020939 ( real) -> 16.547x
|
359
|
+
0.001411915
|
360
|
+
2 GeneratorBenchmarkExt#generator_safe 1000 repeats:
|
361
|
+
569.105020353 ( real) -> 13.296x
|
362
|
+
0.001757145
|
363
|
+
3 GeneratorBenchmarkExt#generator_pretty 900 repeats:
|
364
|
+
482.825371244 ( real) -> 11.280x
|
365
|
+
0.002071142
|
366
|
+
4 GeneratorBenchmarkPure#generator_fast 1000 repeats:
|
367
|
+
62.717626652 ( real) -> 1.465x
|
368
|
+
0.015944481
|
369
|
+
5 GeneratorBenchmarkRails#generator 1000 repeats:
|
370
|
+
43.965681162 ( real) -> 1.027x
|
371
|
+
0.022745013
|
372
|
+
6 GeneratorBenchmarkPure#generator_safe 1000 repeats:
|
373
|
+
43.929073409 ( real) -> 1.026x 7 (>=3859)
|
374
|
+
0.022763968
|
375
|
+
7 GeneratorBenchmarkPure#generator_pretty 1000 repeats:
|
376
|
+
42.802514491 ( real) -> 1.000x 6 (>=3859)
|
377
|
+
0.023363113
|
378
|
+
calls/sec ( time) -> speed covers
|
379
|
+
secs/call
|
380
|
+
```
|
381
|
+
|
382
|
+
## Development
|
383
|
+
|
384
|
+
### Release
|
385
|
+
|
386
|
+
Update the json.gemspec and json-java.gemspec.
|
387
|
+
|
388
|
+
```
|
389
|
+
rbenv shell 2.6.5
|
390
|
+
rake build
|
391
|
+
gem push pkg/json-2.3.0.gem
|
392
|
+
|
393
|
+
rbenv shell jruby-9.2.9.0
|
394
|
+
rake build
|
395
|
+
gem push pkg/json-2.3.0-java.gem
|
396
|
+
```
|
397
|
+
|
398
|
+
## Author
|
399
|
+
|
400
|
+
Florian Frank <mailto:flori@ping.de>
|
401
|
+
|
402
|
+
## License
|
403
|
+
|
404
|
+
Ruby License, see https://www.ruby-lang.org/en/about/license.txt.
|
405
|
+
|
406
|
+
## Download
|
407
|
+
|
408
|
+
The latest version of this library can be downloaded at
|
409
|
+
|
410
|
+
* https://rubygems.org/gems/json
|
411
|
+
|
412
|
+
Online Documentation should be located at
|
413
|
+
|
414
|
+
* https://www.rubydoc.info/gems/json
|
415
|
+
|
416
|
+
[Ragel]: http://www.colm.net/open-source/ragel/
|
@@ -0,0 +1,68 @@
|
|
1
|
+
version = File.foreach(File.join(__dir__, "lib/json/version.rb")) do |line|
|
2
|
+
/^\s*VERSION\s*=\s*'(.*)'/ =~ line and break $1
|
3
|
+
end rescue nil
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "json"
|
7
|
+
s.version = version
|
8
|
+
|
9
|
+
s.summary = "JSON Implementation for Ruby"
|
10
|
+
s.description = "This is a JSON implementation as a Ruby extension in C."
|
11
|
+
s.licenses = ["Ruby"]
|
12
|
+
s.authors = ["Florian Frank"]
|
13
|
+
s.email = "flori@ping.de"
|
14
|
+
|
15
|
+
s.extensions = ["ext/json/ext/generator/extconf.rb", "ext/json/ext/parser/extconf.rb", "ext/json/extconf.rb"]
|
16
|
+
s.extra_rdoc_files = ["README.md"]
|
17
|
+
s.rdoc_options = ["--title", "JSON implementation for Ruby", "--main", "README.md"]
|
18
|
+
s.files = [
|
19
|
+
"CHANGES.md",
|
20
|
+
"LICENSE",
|
21
|
+
"README.md",
|
22
|
+
"ext/json/ext/fbuffer/fbuffer.h",
|
23
|
+
"ext/json/ext/generator/depend",
|
24
|
+
"ext/json/ext/generator/extconf.rb",
|
25
|
+
"ext/json/ext/generator/generator.c",
|
26
|
+
"ext/json/ext/generator/generator.h",
|
27
|
+
"ext/json/ext/parser/depend",
|
28
|
+
"ext/json/ext/parser/extconf.rb",
|
29
|
+
"ext/json/ext/parser/parser.c",
|
30
|
+
"ext/json/ext/parser/parser.h",
|
31
|
+
"ext/json/ext/parser/parser.rl",
|
32
|
+
"ext/json/extconf.rb",
|
33
|
+
"json.gemspec",
|
34
|
+
"lib/json.rb",
|
35
|
+
"lib/json/add/bigdecimal.rb",
|
36
|
+
"lib/json/add/complex.rb",
|
37
|
+
"lib/json/add/core.rb",
|
38
|
+
"lib/json/add/date.rb",
|
39
|
+
"lib/json/add/date_time.rb",
|
40
|
+
"lib/json/add/exception.rb",
|
41
|
+
"lib/json/add/ostruct.rb",
|
42
|
+
"lib/json/add/range.rb",
|
43
|
+
"lib/json/add/rational.rb",
|
44
|
+
"lib/json/add/regexp.rb",
|
45
|
+
"lib/json/add/set.rb",
|
46
|
+
"lib/json/add/struct.rb",
|
47
|
+
"lib/json/add/symbol.rb",
|
48
|
+
"lib/json/add/time.rb",
|
49
|
+
"lib/json/common.rb",
|
50
|
+
"lib/json/ext.rb",
|
51
|
+
"lib/json/generic_object.rb",
|
52
|
+
"lib/json/pure.rb",
|
53
|
+
"lib/json/pure/generator.rb",
|
54
|
+
"lib/json/pure/parser.rb",
|
55
|
+
"lib/json/version.rb",
|
56
|
+
]
|
57
|
+
s.homepage = "https://flori.github.io/json"
|
58
|
+
s.metadata = {
|
59
|
+
'bug_tracker_uri' => 'https://github.com/flori/json/issues',
|
60
|
+
'changelog_uri' => 'https://github.com/flori/json/blob/master/CHANGES.md',
|
61
|
+
'documentation_uri' => 'https://flori.github.io/json/doc/index.html',
|
62
|
+
'homepage_uri' => s.homepage,
|
63
|
+
'source_code_uri' => 'https://github.com/flori/json',
|
64
|
+
'wiki_uri' => 'https://github.com/flori/json/wiki'
|
65
|
+
}
|
66
|
+
|
67
|
+
s.required_ruby_version = Gem::Requirement.new(">= 2.3")
|
68
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Fumiaki MATSUSHIMA
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# LanguageServer::Protocol
|
2
|
+
|
3
|
+
A Language Server Protocol SDK for Ruby.
|
4
|
+
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/language_server-protocol.svg)](https://badge.fury.io/rb/language_server-protocol)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'language_server-protocol'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install language_server-protocol
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Currently, this gem supports only stdio as transport layer out of box.
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
require "language_server-protocol"
|
29
|
+
|
30
|
+
LSP = LanguageServer::Protocol
|
31
|
+
writer = LSP::Transport::Stdio::Writer.new
|
32
|
+
reader = LSP::Transport::Stdio::Reader.new
|
33
|
+
|
34
|
+
subscribers = {
|
35
|
+
initialize: -> {
|
36
|
+
LSP::Interface::InitializeResult.new(
|
37
|
+
capabilities: LSP::Interface::ServerCapabilities.new(
|
38
|
+
text_document_sync: LSP::Interface::TextDocumentSyncOptions.new(
|
39
|
+
change: LSP::Constant::TextDocumentSyncKind::FULL
|
40
|
+
),
|
41
|
+
completion_provider: LSP::Interface::CompletionOptions.new(
|
42
|
+
resolve_provider: true,
|
43
|
+
trigger_characters: %w(.)
|
44
|
+
),
|
45
|
+
definition_provider: true
|
46
|
+
)
|
47
|
+
)
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
reader.read do |request|
|
52
|
+
result = subscribers[request[:method].to_sym].call
|
53
|
+
writer.write(id: request[:id], result: result)
|
54
|
+
exit
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
58
|
+
You can use any IO object as transport layer:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
io = StringIO.new
|
62
|
+
writer = LSP::Transport::Io::Writer.new(io)
|
63
|
+
reader = LSP::Transport::Io::Reader.new(io)
|
64
|
+
```
|
65
|
+
|
66
|
+
## Versioning
|
67
|
+
|
68
|
+
language_server-protocol gem does NOT use semantic versioning.
|
69
|
+
This gem versions are structured as `x.y.z.t`.
|
70
|
+
`x.y.z` indicates the [Language server protocol](https://github.com/Microsoft/language-server-protocol/) version and `t` is a monotonically increasing number.
|
71
|
+
|
72
|
+
## Development
|
73
|
+
|
74
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
75
|
+
|
76
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
77
|
+
|
78
|
+
## Contributing
|
79
|
+
|
80
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/mtsmfm/language_server-protocol-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
81
|
+
|
82
|
+
## License
|
83
|
+
|
84
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
85
|
+
|
86
|
+
## Code of Conduct
|
87
|
+
|
88
|
+
Everyone interacting in the LanguageServer::Protocol project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/mtsmfm/language_server-protocol/blob/master/CODE_OF_CONDUCT.md).
|