rack-hackery 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab296157b15534cdd3251e991126f9debbd5bcdd
4
- data.tar.gz: de3c37a2eec9f218a83e8d8c43e62c9a6d515d80
3
+ metadata.gz: d426083002378d6708042f2920d656b05191c5d3
4
+ data.tar.gz: 4e43421334e00a587c097d00c6cd81b9885bc2f6
5
5
  SHA512:
6
- metadata.gz: 88d50ea51c9110e40b51bc3a5ae1cfd93898d7305af11fbde0bbc500a45e027818d2c2d3d6813b3d07c8bdd13bf03848d4394084659db94e6499aeb981a59591
7
- data.tar.gz: 14d583ec230f011d28ec4e8dabfa62415d9d50b548b57499aa06de08114fa07039e02c35ccc319c460d982e8f55b964f7807d12aaf7c3c918b9d8622c2d21f5e
6
+ metadata.gz: 24a1ca62f97c4961a99a1a38665c38e564535e4c6b53ec3cd9552b577888a6694439a5a3f304149d41180e05ac63fd42275537df371cb0d6188b2c9c3b9b3b85
7
+ data.tar.gz: 788da29b563d86a877c58debcf616670e2652155493ee4f6dd688f4bdb194606d670e324829c5f3acd829425fec527ebfce8ea480965366c9d6262fdf966dbde
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Rack::Hackery
2
2
 
3
- TODO: Write a gem description
3
+ A set of small Rack middlewares collected from here and there...
4
4
 
5
5
  ## Installation
6
6
 
7
- Add this line to your application's Gemfile:
7
+ Add this line to your application's `Gemfile`:
8
8
 
9
9
  ``` ruby
10
10
  gem 'rack-hackery'
@@ -12,25 +12,39 @@ gem 'rack-hackery'
12
12
 
13
13
  And then execute:
14
14
 
15
- $ bundle
15
+ ``` bash
16
+ bundle
17
+ ```
16
18
 
17
19
  Or install it yourself as:
18
20
 
19
- $ gem install rack-hackery
21
+ ``` bash
22
+ gem install rack-hackery
23
+ ```
20
24
 
21
25
  ## What's included
22
26
 
23
- Currently, the only thing here is a modified version of `Rack::ETag` that's supposed to fix the ugly Safari 7/8 ETag
24
- caching problem.
27
+ * A modified version of `Rack::ETag` that's supposed to fix the ugly Safari 7/8 ETag caching problem.
28
+ * A JSON response prettifier.
25
29
 
26
30
  ## Usage
27
31
 
28
- In in either `config/application.rb` or `config/environments/{development,production}.rb`:
32
+ ### Rack::Hackery::Etag
33
+
34
+ In either `config/application.rb` or `config/environments/{development,production}.rb`:
29
35
 
30
36
  ``` ruby
31
37
  config.middleware.swap Rack::ETag, Rack::Hackery::ETag
32
38
  ```
33
39
 
40
+ ### Rack::Hackery::PrettyJsonResponse
41
+
42
+ In either `config/application.rb` or `config/environments/{development,production}.rb`:
43
+
44
+ ``` ruby
45
+ config.middleware.use Rack::Hackery::PrettyJsonResponse
46
+ ```
47
+
34
48
  ## Contributing
35
49
 
36
50
  1. [Fork it](https://github.com/tzvetkoff/rack-hackery/fork)
data/lib/rack/hackery.rb CHANGED
@@ -1,2 +1,3 @@
1
1
  require 'rack/hackery/version'
2
2
  require 'rack/hackery/etag'
3
+ require 'rack/hackery/pretty_json_response'
@@ -0,0 +1,23 @@
1
+ module Rack
2
+ module Hackery
3
+ # Prettify JSON responses
4
+ class PrettyJsonResponse
5
+ def initialize(app)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ status, headers, response = @app.call(env)
11
+
12
+ if headers['Content-Type'] =~ /^application\/json/
13
+ object = JSON.parse(response.body)
14
+ string = JSON.pretty_unparse(object)
15
+ response = [string]
16
+ headers['Content-Length'] = Rack::Utils.bytesize(string).to_s
17
+ end
18
+
19
+ [status, headers, response]
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module Hackery
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.3'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-hackery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Latchezar Tzvetkoff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-14 00:00:00.000000000 Z
11
+ date: 2014-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,7 @@ files:
52
52
  - Rakefile
53
53
  - lib/rack/hackery.rb
54
54
  - lib/rack/hackery/etag.rb
55
+ - lib/rack/hackery/pretty_json_response.rb
55
56
  - lib/rack/hackery/version.rb
56
57
  - rack-hackery.gemspec
57
58
  homepage: ''
@@ -74,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
75
  version: '0'
75
76
  requirements: []
76
77
  rubyforge_project:
77
- rubygems_version: 2.2.2
78
+ rubygems_version: 2.4.3
78
79
  signing_key:
79
80
  specification_version: 4
80
81
  summary: A small collection of Rack hacks.