rack-link_headers 2.4.0 → 2.4.1

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.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rack/link_headers/version.rb +1 -1
  3. data/rack-link-headers.gemspec +2 -2
  4. data/vendor/bundle/ruby/3.3.0/bundler/gems/rubocop-config-943facea9d8f/LICENSE +21 -0
  5. data/vendor/bundle/ruby/3.3.0/bundler/gems/rubocop-config-943facea9d8f/README.md +23 -0
  6. data/vendor/bundle/ruby/3.3.0/bundler/gems/rubocop-config-943facea9d8f/rubocop-config.gemspec +31 -0
  7. data/vendor/bundle/ruby/3.3.0/gems/ast-2.4.2/LICENSE.MIT +20 -0
  8. data/vendor/bundle/ruby/3.3.0/gems/ast-2.4.2/README.YARD.md +12 -0
  9. data/vendor/bundle/ruby/3.3.0/gems/json-2.7.2/LICENSE +56 -0
  10. data/vendor/bundle/ruby/3.3.0/gems/json-2.7.2/README.md +416 -0
  11. data/vendor/bundle/ruby/3.3.0/gems/json-2.7.2/json.gemspec +68 -0
  12. data/vendor/bundle/ruby/3.3.0/gems/language_server-protocol-3.17.0.3/LICENSE.txt +21 -0
  13. data/vendor/bundle/ruby/3.3.0/gems/language_server-protocol-3.17.0.3/README.md +88 -0
  14. data/vendor/bundle/ruby/3.3.0/gems/minitest-5.25.1/README.rdoc +835 -0
  15. data/vendor/bundle/ruby/3.3.0/gems/parallel-1.26.3/MIT-LICENSE.txt +20 -0
  16. data/vendor/bundle/ruby/3.3.0/gems/parser-3.3.5.0/LICENSE.txt +25 -0
  17. data/vendor/bundle/ruby/3.3.0/gems/parser-3.3.5.0/parser.gemspec +43 -0
  18. data/vendor/bundle/ruby/3.3.0/gems/racc-1.8.1/README.ja.rdoc +58 -0
  19. data/vendor/bundle/ruby/3.3.0/gems/racc-1.8.1/README.rdoc +60 -0
  20. data/vendor/bundle/ruby/3.3.0/gems/rack-3.1.7/CHANGELOG.md +994 -0
  21. data/vendor/bundle/ruby/3.3.0/gems/rack-3.1.7/MIT-LICENSE +20 -0
  22. data/vendor/bundle/ruby/3.3.0/gems/rack-3.1.7/README.md +328 -0
  23. data/vendor/bundle/ruby/3.3.0/gems/rainbow-3.1.1/LICENSE +20 -0
  24. data/vendor/bundle/ruby/3.3.0/gems/rainbow-3.1.1/README.markdown +227 -0
  25. data/vendor/bundle/ruby/3.3.0/gems/rake-13.2.1/MIT-LICENSE +21 -0
  26. data/vendor/bundle/ruby/3.3.0/gems/rake-13.2.1/README.rdoc +155 -0
  27. data/vendor/bundle/ruby/3.3.0/gems/rake-13.2.1/rake.gemspec +101 -0
  28. data/vendor/bundle/ruby/3.3.0/gems/rake-release-1.3.0/LICENSE +21 -0
  29. data/vendor/bundle/ruby/3.3.0/gems/rake-release-1.3.0/README.md +107 -0
  30. data/vendor/bundle/ruby/3.3.0/gems/rake-release-1.3.0/rake-release.gemspec +23 -0
  31. data/vendor/bundle/ruby/3.3.0/gems/regexp_parser-2.9.2/LICENSE +22 -0
  32. data/vendor/bundle/ruby/3.3.0/gems/regexp_parser-2.9.2/regexp_parser.gemspec +34 -0
  33. data/vendor/bundle/ruby/3.3.0/gems/rexml-3.3.7/LICENSE.txt +22 -0
  34. data/vendor/bundle/ruby/3.3.0/gems/rexml-3.3.7/README.md +57 -0
  35. data/vendor/bundle/ruby/3.3.0/gems/rubocop-1.65.1/LICENSE.txt +20 -0
  36. data/vendor/bundle/ruby/3.3.0/gems/rubocop-1.65.1/README.md +251 -0
  37. data/vendor/bundle/ruby/3.3.0/gems/rubocop-ast-1.32.3/LICENSE.txt +20 -0
  38. data/vendor/bundle/ruby/3.3.0/gems/rubocop-ast-1.32.3/README.md +56 -0
  39. data/vendor/bundle/ruby/3.3.0/gems/rubocop-capybara-2.21.0/CHANGELOG.md +85 -0
  40. data/vendor/bundle/ruby/3.3.0/gems/rubocop-capybara-2.21.0/MIT-LICENSE.md +21 -0
  41. data/vendor/bundle/ruby/3.3.0/gems/rubocop-capybara-2.21.0/README.md +88 -0
  42. data/vendor/bundle/ruby/3.3.0/gems/rubocop-factory_bot-2.26.1/CHANGELOG.md +116 -0
  43. data/vendor/bundle/ruby/3.3.0/gems/rubocop-factory_bot-2.26.1/MIT-LICENSE.md +21 -0
  44. data/vendor/bundle/ruby/3.3.0/gems/rubocop-factory_bot-2.26.1/README.md +88 -0
  45. data/vendor/bundle/ruby/3.3.0/gems/rubocop-performance-1.21.1/LICENSE.txt +20 -0
  46. data/vendor/bundle/ruby/3.3.0/gems/rubocop-performance-1.21.1/README.md +97 -0
  47. data/vendor/bundle/ruby/3.3.0/gems/rubocop-rspec-3.0.5/CHANGELOG.md +1034 -0
  48. data/vendor/bundle/ruby/3.3.0/gems/rubocop-rspec-3.0.5/MIT-LICENSE.md +21 -0
  49. data/vendor/bundle/ruby/3.3.0/gems/rubocop-rspec-3.0.5/README.md +109 -0
  50. data/vendor/bundle/ruby/3.3.0/gems/rubocop-rspec_rails-2.30.0/CHANGELOG.md +84 -0
  51. data/vendor/bundle/ruby/3.3.0/gems/rubocop-rspec_rails-2.30.0/MIT-LICENSE.md +21 -0
  52. data/vendor/bundle/ruby/3.3.0/gems/rubocop-rspec_rails-2.30.0/README.md +90 -0
  53. data/vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/LICENSE.txt +19 -0
  54. data/vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/README.md +131 -0
  55. data/vendor/bundle/ruby/3.3.0/gems/unicode-display_width-2.6.0/CHANGELOG.md +200 -0
  56. data/vendor/bundle/ruby/3.3.0/gems/unicode-display_width-2.6.0/MIT-LICENSE.txt +22 -0
  57. data/vendor/bundle/ruby/3.3.0/gems/unicode-display_width-2.6.0/README.md +171 -0
  58. data/vendor/bundle/ruby/3.3.0/specifications/ast-2.4.2.gemspec +30 -0
  59. data/vendor/bundle/ruby/3.3.0/specifications/json-2.7.2.gemspec +0 -0
  60. data/vendor/bundle/ruby/3.3.0/specifications/language_server-protocol-3.17.0.3.gemspec +31 -0
  61. data/vendor/bundle/ruby/3.3.0/specifications/minitest-5.25.1.gemspec +31 -0
  62. data/vendor/bundle/ruby/3.3.0/specifications/parallel-1.26.3.gemspec +21 -0
  63. data/vendor/bundle/ruby/3.3.0/specifications/parser-3.3.5.0.gemspec +37 -0
  64. data/vendor/bundle/ruby/3.3.0/specifications/racc-1.8.1.gemspec +28 -0
  65. data/vendor/bundle/ruby/3.3.0/specifications/rack-3.1.7.gemspec +31 -0
  66. data/vendor/bundle/ruby/3.3.0/specifications/rainbow-3.1.1.gemspec +25 -0
  67. data/vendor/bundle/ruby/3.3.0/specifications/rake-13.2.1.gemspec +26 -0
  68. data/vendor/bundle/ruby/3.3.0/specifications/rake-release-1.3.0.gemspec +26 -0
  69. data/vendor/bundle/ruby/3.3.0/specifications/regexp_parser-2.9.2.gemspec +22 -0
  70. data/vendor/bundle/ruby/3.3.0/specifications/rexml-3.3.7.gemspec +25 -0
  71. data/vendor/bundle/ruby/3.3.0/specifications/rubocop-1.65.1.gemspec +39 -0
  72. data/vendor/bundle/ruby/3.3.0/specifications/rubocop-ast-1.32.3.gemspec +28 -0
  73. data/vendor/bundle/ruby/3.3.0/specifications/rubocop-capybara-2.21.0.gemspec +27 -0
  74. data/vendor/bundle/ruby/3.3.0/specifications/rubocop-factory_bot-2.26.1.gemspec +27 -0
  75. data/vendor/bundle/ruby/3.3.0/specifications/rubocop-performance-1.21.1.gemspec +29 -0
  76. data/vendor/bundle/ruby/3.3.0/specifications/rubocop-rspec-3.0.5.gemspec +28 -0
  77. data/vendor/bundle/ruby/3.3.0/specifications/rubocop-rspec_rails-2.30.0.gemspec +28 -0
  78. data/vendor/bundle/ruby/3.3.0/specifications/ruby-progressbar-1.13.0.gemspec +29 -0
  79. data/vendor/bundle/ruby/3.3.0/specifications/unicode-display_width-2.6.0.gemspec +29 -0
  80. metadata +80 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 671eeb60f4abb81feaee2bbe86a0ab04bf2608d47b27aa6c0bc2560d8171c327
4
- data.tar.gz: ad43357571a86ed6732079cad2785f62b18c6f9f970f72c5b73332c8f9114d92
3
+ metadata.gz: 57a81bf01183fdf056a8dadb9023a9ed16e642a443a83becff3883a4ed7e43a0
4
+ data.tar.gz: ef633cf91d972574500d48cca6bf4cddc14236262a23d482f6b1709bca9cc98d
5
5
  SHA512:
6
- metadata.gz: 336743659f0eb6c603d2ab6da5f9d27f9057eb1f82ce2180549954b5339ada7836630bbfe349178a5fcf92aa65cbc90f00798f25bcc7383b86069b56b9e75cfd
7
- data.tar.gz: edb4cea104f72b958f73dad53405cf3049572a0eb518e7d070f1fe78f5f49326ac77a0a22c5c9a4b41ba3999472fcd1f617fab86d86862b447349d57a376f7e6
6
+ metadata.gz: fa10a5334f0bee37f3259002daf6be7f551f863b90f49492e4d68efd2bd2a5259617fbf6d7d6fc97cf4742fac25f1945f4bf1c1f15598ae936aba68b1a469f47
7
+ data.tar.gz: 8c6c3c36f07588bc18426ebf547c496e7c898fb536a8ff6ed118fce15f353f6449b512c6c24c6e3915c19a2c7993fcde93949ce2ec7608c236a0d66fd4ff1550
@@ -5,7 +5,7 @@ module Rack
5
5
  module VERSION
6
6
  MAJOR = 2
7
7
  MINOR = 4
8
- PATCH = 0
8
+ PATCH = 1
9
9
  STAGE = nil
10
10
 
11
11
  def self.to_s
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.authors = ['Jan Graichen']
12
12
  spec.email = ['jgraichen@altimos.de']
13
13
  spec.summary = 'Easy Link header management for rack responses.'
14
- spec.homepage = ''
14
+ spec.homepage = 'https://github.com/jgraichen/rack-link_headers'
15
15
  spec.license = 'MIT'
16
16
 
17
17
  spec.required_ruby_version = '>= 2.7.0'
@@ -25,5 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.executables = spec.files.grep(%r{^bin/}) {|f| File.basename(f) }
26
26
  spec.require_paths = ['lib']
27
27
 
28
- spec.add_runtime_dependency 'rack'
28
+ spec.add_dependency 'rack'
29
29
  end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Jan Graichen
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,23 @@
1
+ # Shared Rubocop Configuration
2
+
3
+ Shared rubocop configuration and defaults for my libraries and projects.
4
+
5
+ ## Usage
6
+
7
+ ```ruby
8
+ # Gemfile
9
+
10
+ gem 'rubocop-config', github: 'jgraichen/rubocop-config', ref: 'v11', require: false
11
+ ```
12
+
13
+ ```yaml
14
+ # .rubocop.yml
15
+
16
+ inherit_gem:
17
+ rubocop-config: default.yml
18
+
19
+ AllCops:
20
+ TargetRubyVersion: 2.7
21
+ SuggestExtensions: False
22
+ NewCops: enable
23
+ ```
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # stub: rubocop-config 11.0.0 ruby lib
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "rubocop-config".freeze
6
+ s.version = "11.0.0".freeze
7
+
8
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
+ s.metadata = { "allowed_push_host" => ".", "rubygems_mfa_required" => "true" } if s.respond_to? :metadata=
10
+ s.require_paths = ["lib".freeze]
11
+ s.authors = ["Jan Graichen".freeze]
12
+ s.date = "2024-09-27"
13
+ s.email = ["jgraichen@altimos.de".freeze]
14
+ s.files = ["LICENSE".freeze, "README.md".freeze, "default.yml".freeze]
15
+ s.homepage = "https://github.com/jgraichen/rubocop-config".freeze
16
+ s.licenses = ["MIT".freeze]
17
+ s.required_ruby_version = Gem::Requirement.new(">= 2.7.0".freeze)
18
+ s.rubygems_version = "3.5.16".freeze
19
+ s.summary = "Shared rubocop config".freeze
20
+
21
+ s.installed_by_version = "3.5.16".freeze if s.respond_to? :installed_by_version
22
+
23
+ s.specification_version = 4
24
+
25
+ s.add_runtime_dependency(%q<rubocop>.freeze, ["~> 1.65.0".freeze])
26
+ s.add_runtime_dependency(%q<rubocop-performance>.freeze, ["~> 1.21.1".freeze])
27
+ s.add_runtime_dependency(%q<rubocop-rspec>.freeze, ["~> 3.0.2".freeze])
28
+ s.add_runtime_dependency(%q<rubocop-capybara>.freeze, ["~> 2.21.0".freeze])
29
+ s.add_runtime_dependency(%q<rubocop-factory_bot>.freeze, ["~> 2.26.1".freeze])
30
+ s.add_runtime_dependency(%q<rubocop-rspec_rails>.freeze, ["~> 2.30.0".freeze])
31
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011-2013 Peter Zotov <whitequark@whitequark.org>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a
4
+ copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included
12
+ in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,12 @@
1
+ {AST} is a library for manipulating abstract syntax trees.
2
+
3
+ It embraces immutability; each AST node is inherently frozen at
4
+ creation, and updating a child node requires recreating that node
5
+ and its every parent, recursively.
6
+
7
+ This is a design choice. It does create some pressure on
8
+ garbage collector, but completely eliminates all concurrency
9
+ and aliasing problems.
10
+
11
+ See also {AST::Node}, {AST::Processor::Mixin} and {AST::Sexp} for
12
+ additional recommendations and design patterns.
@@ -0,0 +1,56 @@
1
+ Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
2
+ You can redistribute it and/or modify it under either the terms of the
3
+ 2-clause BSDL (see the file BSDL), or the conditions below:
4
+
5
+ 1. You may make and give away verbatim copies of the source form of the
6
+ software without restriction, provided that you duplicate all of the
7
+ original copyright notices and associated disclaimers.
8
+
9
+ 2. You may modify your copy of the software in any way, provided that
10
+ you do at least ONE of the following:
11
+
12
+ a) place your modifications in the Public Domain or otherwise
13
+ make them Freely Available, such as by posting said
14
+ modifications to Usenet or an equivalent medium, or by allowing
15
+ the author to include your modifications in the software.
16
+
17
+ b) use the modified software only within your corporation or
18
+ organization.
19
+
20
+ c) give non-standard binaries non-standard names, with
21
+ instructions on where to get the original software distribution.
22
+
23
+ d) make other distribution arrangements with the author.
24
+
25
+ 3. You may distribute the software in object code or binary form,
26
+ provided that you do at least ONE of the following:
27
+
28
+ a) distribute the binaries and library files of the software,
29
+ together with instructions (in the manual page or equivalent)
30
+ on where to get the original distribution.
31
+
32
+ b) accompany the distribution with the machine-readable source of
33
+ the software.
34
+
35
+ c) give non-standard binaries non-standard names, with
36
+ instructions on where to get the original software distribution.
37
+
38
+ d) make other distribution arrangements with the author.
39
+
40
+ 4. You may modify and include the part of the software into any other
41
+ software (possibly commercial). But some files in the distribution
42
+ are not written by the author, so that they are not under these terms.
43
+
44
+ For the list of those files and their copying conditions, see the
45
+ file LEGAL.
46
+
47
+ 5. The scripts and library files supplied as input to or produced as
48
+ output from the software do not automatically fall under the
49
+ copyright of the software, but belong to whomever generated them,
50
+ and may be sold commercially, and may be aggregated with this
51
+ software.
52
+
53
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
54
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
55
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
56
+ PURPOSE.
@@ -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/