olive_branch 3.0.0 → 4.0.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/README.md +28 -3
- data/lib/olive_branch/version.rb +1 -1
- metadata +5 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bec73b70112a823836210ff185bcf853dfa2d7417be60ddab5e9d2e37d59f37
|
4
|
+
data.tar.gz: 8c494c373619e9543d0ccb28bbafe3664edc32d3a975a220c052a9422fce916e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ca6f8224a09fa9113a6e6c0caa45cb928f2eba5ed2538a06e2726d931892af3a31e31c1ca7fb90cec95e7392a5a3cc9a21b8be9427f0af4b50ee3f73672bc86
|
7
|
+
data.tar.gz: b949f436070efe153eb34c11b9677a0f86b8999406630753cc726de5387d5d266b856afd30c028e24df733c93669a673d4919ca922c91517cc9f9bca8f31c628
|
data/README.md
CHANGED
@@ -13,12 +13,24 @@ This gem lets your API users pass in and receive camelCased or dash-cased keys,
|
|
13
13
|
gem "olive_branch"
|
14
14
|
```
|
15
15
|
|
16
|
-
2. Add this to `config/applcation.rb
|
16
|
+
2. Add this to `config/applcation.rb` if you want the clients to control the transformation behaviour through the `Key-Inflection` HTTP header sent by the client:
|
17
17
|
|
18
18
|
```ruby
|
19
19
|
config.middleware.use OliveBranch::Middleware
|
20
20
|
```
|
21
21
|
|
22
|
+
Alternative, if you want to always convert between snake_case and camelCase for your API and only your API, to keep Rubyist and JavaScript developer's happy, use the following configuration:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
excluded_routes = ->(env) { !env["PATH_INFO"].match(%r{^/api}) }
|
26
|
+
config.middleware.use OliveBranch::Middleware,
|
27
|
+
inflection: "camel",
|
28
|
+
exclude_params: excluded_routes,
|
29
|
+
exclude_response: excluded_routes
|
30
|
+
```
|
31
|
+
|
32
|
+
in your `config/application.rb`.
|
33
|
+
|
22
34
|
## Use
|
23
35
|
|
24
36
|
Include a `Key-Inflection` header with values of `camel`, `dash`, `snake` or `pascal` in your JSON API requests.
|
@@ -27,7 +39,8 @@ For more examples, see [our blog post](https://www.viget.com/articles/introducin
|
|
27
39
|
|
28
40
|
## Optimizations and configuration
|
29
41
|
|
30
|
-
`OliveBranch` uses `multi_json`, which will choose the fastest available JSON parsing library
|
42
|
+
`OliveBranch` uses `multi_json`, which will automatically choose the fastest available JSON parsing library present in your application.
|
43
|
+
Most Ruby applications default to using the JSON library that ships with Ruby. However, by including a coder that `multi_json` considers faster, like [Oj](https://github.com/ohler55/oj) in your gemfile, you can potentially save up to ~20% response time.
|
31
44
|
|
32
45
|
The middleware can be initialized with custom camelize/dasherize implementations, so if you know you have a fixed size set of keys, you can save a considerable amount of time by providing a custom camelize that caches like so:
|
33
46
|
|
@@ -54,7 +67,7 @@ Default inflection header key can be changed like
|
|
54
67
|
config.middleware.use OliveBranch::Middleware, inflection_header: 'Inflect-With'
|
55
68
|
```
|
56
69
|
|
57
|
-
A default inflection can be specified so you don't have to include the `Key-Inflection` header on every request.
|
70
|
+
A default inflection can be specified so you don't have to include the `Key-Inflection` header on every request. If you opt for default inflection, you may want to exclude the routes that Rails uses (see Filtering).
|
58
71
|
|
59
72
|
```ruby
|
60
73
|
config.middleware.use OliveBranch::Middleware, inflection: 'camel'
|
@@ -94,6 +107,18 @@ config.middleware.use OliveBranch::Middleware, exclude_response: -> (env) {
|
|
94
107
|
}
|
95
108
|
```
|
96
109
|
|
110
|
+
#### Rails routes & Action Text
|
111
|
+
|
112
|
+
If you're using default inflection, exclude the routes that Rails uses
|
113
|
+
```ruby
|
114
|
+
rails_routes = -> (env) { env['PATH_INFO'].match(/^\/rails/) }
|
115
|
+
config.middleware.use OliveBranch::Middleware, inflection: "camel", exclude_params: rails_routes, exclude_response: rails_routes
|
116
|
+
```
|
117
|
+
|
118
|
+
## Upgrading to version 3
|
119
|
+
|
120
|
+
Default inflection header changed from `X-Key-Inflection` to `Key-Inflection`.
|
121
|
+
|
97
122
|
## Troubleshooting
|
98
123
|
|
99
124
|
We've seen folks raise issues that inbound transformations are not taking place. This is often due to the fact that OliveBranch, by default, is only transforming keys when a request's Content-Type is `application/json`.
|
data/lib/olive_branch/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: olive_branch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eli Fatsi
|
8
8
|
- David Eisinger
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-04-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -39,20 +39,6 @@ dependencies:
|
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
|
-
- !ruby/object:Gem::Dependency
|
43
|
-
name: oj
|
44
|
-
requirement: !ruby/object:Gem::Requirement
|
45
|
-
requirements:
|
46
|
-
- - ">="
|
47
|
-
- !ruby/object:Gem::Version
|
48
|
-
version: '0'
|
49
|
-
type: :runtime
|
50
|
-
prerelease: false
|
51
|
-
version_requirements: !ruby/object:Gem::Requirement
|
52
|
-
requirements:
|
53
|
-
- - ">="
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version: '0'
|
56
42
|
- !ruby/object:Gem::Dependency
|
57
43
|
name: rspec
|
58
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,7 +98,7 @@ homepage: https://github.com/vigetlabs/olive_branch
|
|
112
98
|
licenses:
|
113
99
|
- MIT
|
114
100
|
metadata: {}
|
115
|
-
post_install_message:
|
101
|
+
post_install_message:
|
116
102
|
rdoc_options: []
|
117
103
|
require_paths:
|
118
104
|
- lib
|
@@ -128,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
114
|
version: '0'
|
129
115
|
requirements: []
|
130
116
|
rubygems_version: 3.0.1
|
131
|
-
signing_key:
|
117
|
+
signing_key:
|
132
118
|
specification_version: 4
|
133
119
|
summary: Handle camel/snake/dash case conversion
|
134
120
|
test_files: []
|