safe_pretty_json 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +20 -0
- data/lib/safe_pretty_json/rack_middleware.rb +19 -0
- data/lib/safe_pretty_json/version.rb +1 -1
- data/lib/safe_pretty_json.rb +1 -0
- data/safe_pretty_json.gemspec +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aeb2e8186b19509836db8d56e0c484e9de036d15be33629ff9dfd68119f71aaf
|
4
|
+
data.tar.gz: '059c580ff86069a5609c517413b950a710947e03167f5199f420552059611c1e'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0f01c59ad5b2a029aa0ab613287b7fb129c7d1f4c0bce70ab0a0d60db9af6a0d61a220d4cf99c3b3858be7b144fa123ecea6c62e8e31fdd6837a4d0e73e501b
|
7
|
+
data.tar.gz: 153f3f53e3393a7b4a1ff7e78b1af3bb99c1cc41fad70e1f80dce63d4f35b6b5980b68f0219b286ebadad26bf9022cde9896db8e0dc6ed046e1ef8e272ce9aeb
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -20,7 +20,27 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
+
```ruby
|
23
24
|
SafePrettyJson.prettify('{ "a": 1 }')
|
25
|
+
```
|
26
|
+
|
27
|
+
SafePrettyJson.prettify doesn't validate if the input string is valid json.
|
28
|
+
If the input is invalid, prettify returns a string whose contents are undefined.
|
29
|
+
|
30
|
+
## Benchmark
|
31
|
+
|
32
|
+
```bash
|
33
|
+
ruby bench/bench.rb
|
34
|
+
```
|
35
|
+
|
36
|
+
- simple: JSON.pretty_generate(JSON.parse(input))
|
37
|
+
- safe_pretty_json: this gem
|
38
|
+
|
39
|
+
```
|
40
|
+
user system total real
|
41
|
+
simple 9.720000 0.000000 9.720000 ( 9.725314)
|
42
|
+
safe_pretty_json 0.860000 0.000000 0.860000 ( 0.859912)
|
43
|
+
```
|
24
44
|
|
25
45
|
## Development
|
26
46
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SafePrettyJson
|
4
|
+
class RackMiddleware
|
5
|
+
def initialize(app)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
status, headers, response = @app.call(env)
|
11
|
+
if %r{^application\/json}.match?(headers['Content-Type'])
|
12
|
+
prettified = SafePrettyJson.prettify(response.body)
|
13
|
+
response = [prettified]
|
14
|
+
headers['Content-Length'] = prettified.bytesize.to_s
|
15
|
+
end
|
16
|
+
[status, headers, response]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/safe_pretty_json.rb
CHANGED
data/safe_pretty_json.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
# Specify which files should be added to the gem when it is released.
|
19
19
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
20
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
21
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|.circleci)/|safe_pretty_json-.*\.gem}) }
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|.circleci|bench)/|safe_pretty_json-.*\.gem}) }
|
22
22
|
end
|
23
23
|
spec.bindir = 'exe'
|
24
24
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: safe_pretty_json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- contribu
|
@@ -103,6 +103,7 @@ files:
|
|
103
103
|
- ext/safe_pretty_json/extconf.rb
|
104
104
|
- ext/safe_pretty_json/safe_pretty_json.cpp
|
105
105
|
- lib/safe_pretty_json.rb
|
106
|
+
- lib/safe_pretty_json/rack_middleware.rb
|
106
107
|
- lib/safe_pretty_json/version.rb
|
107
108
|
- safe_pretty_json.gemspec
|
108
109
|
homepage: https://github.com/contribu/safe_pretty_json
|