olive_branch 1.0.0 → 1.0.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.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/olive_branch/middleware.rb +15 -11
- data/lib/olive_branch/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57c893d626504869e2eacd978f3f267545f8e84b
|
4
|
+
data.tar.gz: 020ffd7265062ac8bf6fa461eaf00102fa14f923
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b14b69a93aa6f614cb47c7b1f7755953aae47cfb97652a520a1959b74bb2af468212fb047f2d09d92ab6fea85625985b0a6aa2084d0fe63835669bf60b31d492
|
7
|
+
data.tar.gz: c01c628795936ba94a4da782eb4a3a41b7b1269419e24c743d83876336c5ede5082e20be964a060b3ee9f5d33213d38f6040e65dd096624a3c43451da5a77995
|
data/README.md
CHANGED
@@ -8,11 +8,11 @@ This gem lets your API users pass in and receive camelCased or dash-cased keys,
|
|
8
8
|
|
9
9
|
1. Add this to your Gemfile and then `bundle install`:
|
10
10
|
|
11
|
-
|
11
|
+
gem "olive_branch"
|
12
12
|
|
13
13
|
2. Add this to `config/applcation.rb`:
|
14
14
|
|
15
|
-
|
15
|
+
config.middleware.use "OliveBranch::Middleware"
|
16
16
|
|
17
17
|
## Use
|
18
18
|
|
@@ -11,20 +11,24 @@ module OliveBranch
|
|
11
11
|
env["action_dispatch.request.request_parameters"].deep_transform_keys!(&:underscore)
|
12
12
|
end
|
13
13
|
|
14
|
-
|
14
|
+
@app.call(env).tap do |_status, headers, response|
|
15
|
+
if inflection && headers["Content-Type"] =~ /application\/json/
|
16
|
+
response.each do |body|
|
17
|
+
begin
|
18
|
+
new_response = JSON.parse(body)
|
19
|
+
rescue JSON::ParserError
|
20
|
+
next
|
21
|
+
end
|
15
22
|
|
16
|
-
|
17
|
-
|
23
|
+
if inflection == "camel"
|
24
|
+
new_response.deep_transform_keys! { |k| k.camelize(:lower) }
|
25
|
+
elsif inflection == "dash"
|
26
|
+
new_response.deep_transform_keys!(&:dasherize)
|
27
|
+
end
|
18
28
|
|
19
|
-
|
20
|
-
|
21
|
-
elsif inflection == "dash"
|
22
|
-
new_response.deep_transform_keys!(&:dasherize)
|
29
|
+
body.replace(new_response.to_json)
|
30
|
+
end
|
23
31
|
end
|
24
|
-
|
25
|
-
[status, headers, [new_response.to_json]]
|
26
|
-
else
|
27
|
-
[status, headers, response]
|
28
32
|
end
|
29
33
|
end
|
30
34
|
end
|
data/lib/olive_branch/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: olive_branch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eli Fatsi
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-04-
|
12
|
+
date: 2016-04-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -25,6 +25,20 @@ dependencies:
|
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '4.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rspec
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '3.2'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '3.2'
|
28
42
|
description: Handle camel/snake/dash case conversion
|
29
43
|
email:
|
30
44
|
- eli.fatsi@viget.com
|