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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d1b78dd20feb4b80c05a31f20f302e0eec006d2b37b8f11193287c0f4182e6cb
4
- data.tar.gz: 3d0fe1ff2036eb366119bb5eec754a40f00599f3feb77cbd3d842ca428e7fd7b
3
+ metadata.gz: aeb2e8186b19509836db8d56e0c484e9de036d15be33629ff9dfd68119f71aaf
4
+ data.tar.gz: '059c580ff86069a5609c517413b950a710947e03167f5199f420552059611c1e'
5
5
  SHA512:
6
- metadata.gz: 2f74c860339849ca9e3c850e0d45ee2ad4141cfb43953e8c00b0798620c632bbeae8d1c5d1fc2c249454d6cbf4c98d45cde76f0696255dde10c0b74ab4eec708
7
- data.tar.gz: 307245b810aa6fb320a41fb6ce67672eee1498eb6d4456367d9d59330fcb35f2982c5ea4fe968ec481e590470a019b8b0f48cfa9b29d5676b8a620554b62b9f3
6
+ metadata.gz: e0f01c59ad5b2a029aa0ab613287b7fb129c7d1f4c0bce70ab0a0d60db9af6a0d61a220d4cf99c3b3858be7b144fa123ecea6c62e8e31fdd6837a4d0e73e501b
7
+ data.tar.gz: 153f3f53e3393a7b4a1ff7e78b1af3bb99c1cc41fad70e1f80dce63d4f35b6b5980b68f0219b286ebadad26bf9022cde9896db8e0dc6ed046e1ef8e272ce9aeb
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- safe_pretty_json (0.1.0)
4
+ safe_pretty_json (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SafePrettyJson
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'safe_pretty_json/safe_pretty_json'
4
+ require 'safe_pretty_json/rack_middleware'
4
5
  require 'safe_pretty_json/version'
@@ -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.1.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