camel_patrol 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.rubocop.yml +78 -0
- data/.travis.yml +17 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +120 -0
- data/LICENSE.txt +21 -0
- data/README.md +66 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/camel_patrol.gemspec +25 -0
- data/gemfiles/Gemfile.rails-4.2-stable +5 -0
- data/gemfiles/Gemfile.rails-4.2-stable.lock +119 -0
- data/lib/camel_patrol.rb +4 -0
- data/lib/camel_patrol/middleware.rb +51 -0
- data/lib/camel_patrol/version.rb +3 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7069a2551a3b939b3d53adb9f25acb8b68815a52
|
4
|
+
data.tar.gz: 9bbe9081f0957fbfc977ea99f4fa245cb4aec679
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b39a003745d7ae5f02c05ee707ee7003d0d0a1f8273c711ead03d0da8fae9feacb6264981ec2489d529cc9988a0b25b3d91cbb9a040a0fe193e09730fb39437d
|
7
|
+
data.tar.gz: 07345b967978804a0542da7fbe4530a8c700bcf52f53a7bc37a139e00c3ef4d755d4826888cfd623df5f08365311d7370e2a1e8631c3e969ec603b7f77e90dab
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
AllCops:
|
2
|
+
DisplayCopNames: true
|
3
|
+
Exclude:
|
4
|
+
- 'db/schema.rb'
|
5
|
+
TargetRubyVersion: 2.2
|
6
|
+
|
7
|
+
Rails:
|
8
|
+
Enabled: true
|
9
|
+
|
10
|
+
Metrics/ClassLength:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Metrics/LineLength:
|
14
|
+
Max: 120
|
15
|
+
|
16
|
+
Metrics/MethodLength:
|
17
|
+
CountComments: false # count full line comments?
|
18
|
+
Max: 20
|
19
|
+
|
20
|
+
Style/Alias:
|
21
|
+
EnforcedStyle: prefer_alias_method
|
22
|
+
|
23
|
+
Style/AlignParameters:
|
24
|
+
Enabled: false
|
25
|
+
|
26
|
+
Style/ClassAndModuleChildren:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
Style/Documentation:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
Style/DotPosition:
|
33
|
+
EnforcedStyle: trailing
|
34
|
+
|
35
|
+
Style/DoubleNegation:
|
36
|
+
Enabled: false
|
37
|
+
|
38
|
+
Style/EmptyLinesAroundBlockBody:
|
39
|
+
Enabled: false
|
40
|
+
|
41
|
+
Style/MultilineOperationIndentation:
|
42
|
+
Enabled: false
|
43
|
+
|
44
|
+
Style/MultilineMethodCallIndentation:
|
45
|
+
EnforcedStyle: indented_relative_to_receiver
|
46
|
+
|
47
|
+
Style/PercentLiteralDelimiters:
|
48
|
+
Enabled: false
|
49
|
+
|
50
|
+
Style/SignalException:
|
51
|
+
Enabled: false
|
52
|
+
|
53
|
+
Style/StringLiterals:
|
54
|
+
Enabled: false
|
55
|
+
|
56
|
+
Style/TrailingCommaInArguments:
|
57
|
+
Enabled: false
|
58
|
+
|
59
|
+
Style/TrailingCommaInLiteral:
|
60
|
+
Enabled: false
|
61
|
+
|
62
|
+
Style/WordArray:
|
63
|
+
Enabled: false
|
64
|
+
|
65
|
+
Lint/Void:
|
66
|
+
Enabled: false
|
67
|
+
|
68
|
+
Lint/AmbiguousRegexpLiteral:
|
69
|
+
Enabled: false
|
70
|
+
|
71
|
+
Lint/AmbiguousOperator:
|
72
|
+
Enabled: false
|
73
|
+
|
74
|
+
Style/AndOr:
|
75
|
+
EnforcedStyle: conditionals
|
76
|
+
|
77
|
+
Style/VariableNumber:
|
78
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
camel_patrol (1.0.0)
|
5
|
+
railties (>= 4.1.0, < 5.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actioncable (5.0.0.1)
|
11
|
+
actionpack (= 5.0.0.1)
|
12
|
+
nio4r (~> 1.2)
|
13
|
+
websocket-driver (~> 0.6.1)
|
14
|
+
actionmailer (5.0.0.1)
|
15
|
+
actionpack (= 5.0.0.1)
|
16
|
+
actionview (= 5.0.0.1)
|
17
|
+
activejob (= 5.0.0.1)
|
18
|
+
mail (~> 2.5, >= 2.5.4)
|
19
|
+
rails-dom-testing (~> 2.0)
|
20
|
+
actionpack (5.0.0.1)
|
21
|
+
actionview (= 5.0.0.1)
|
22
|
+
activesupport (= 5.0.0.1)
|
23
|
+
rack (~> 2.0)
|
24
|
+
rack-test (~> 0.6.3)
|
25
|
+
rails-dom-testing (~> 2.0)
|
26
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
27
|
+
actionview (5.0.0.1)
|
28
|
+
activesupport (= 5.0.0.1)
|
29
|
+
builder (~> 3.1)
|
30
|
+
erubis (~> 2.7.0)
|
31
|
+
rails-dom-testing (~> 2.0)
|
32
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
33
|
+
activejob (5.0.0.1)
|
34
|
+
activesupport (= 5.0.0.1)
|
35
|
+
globalid (>= 0.3.6)
|
36
|
+
activemodel (5.0.0.1)
|
37
|
+
activesupport (= 5.0.0.1)
|
38
|
+
activerecord (5.0.0.1)
|
39
|
+
activemodel (= 5.0.0.1)
|
40
|
+
activesupport (= 5.0.0.1)
|
41
|
+
arel (~> 7.0)
|
42
|
+
activesupport (5.0.0.1)
|
43
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
44
|
+
i18n (~> 0.7)
|
45
|
+
minitest (~> 5.1)
|
46
|
+
tzinfo (~> 1.1)
|
47
|
+
arel (7.1.4)
|
48
|
+
builder (3.2.2)
|
49
|
+
concurrent-ruby (1.0.2)
|
50
|
+
erubis (2.7.0)
|
51
|
+
globalid (0.3.7)
|
52
|
+
activesupport (>= 4.1.0)
|
53
|
+
i18n (0.7.0)
|
54
|
+
loofah (2.0.3)
|
55
|
+
nokogiri (>= 1.5.9)
|
56
|
+
mail (2.6.4)
|
57
|
+
mime-types (>= 1.16, < 4)
|
58
|
+
method_source (0.8.2)
|
59
|
+
mime-types (3.1)
|
60
|
+
mime-types-data (~> 3.2015)
|
61
|
+
mime-types-data (3.2016.0521)
|
62
|
+
mini_portile2 (2.1.0)
|
63
|
+
minitest (5.9.1)
|
64
|
+
nio4r (1.2.1)
|
65
|
+
nokogiri (1.6.8.1)
|
66
|
+
mini_portile2 (~> 2.1.0)
|
67
|
+
rack (2.0.1)
|
68
|
+
rack-test (0.6.3)
|
69
|
+
rack (>= 1.0)
|
70
|
+
rails (5.0.0.1)
|
71
|
+
actioncable (= 5.0.0.1)
|
72
|
+
actionmailer (= 5.0.0.1)
|
73
|
+
actionpack (= 5.0.0.1)
|
74
|
+
actionview (= 5.0.0.1)
|
75
|
+
activejob (= 5.0.0.1)
|
76
|
+
activemodel (= 5.0.0.1)
|
77
|
+
activerecord (= 5.0.0.1)
|
78
|
+
activesupport (= 5.0.0.1)
|
79
|
+
bundler (>= 1.3.0, < 2.0)
|
80
|
+
railties (= 5.0.0.1)
|
81
|
+
sprockets-rails (>= 2.0.0)
|
82
|
+
rails-dom-testing (2.0.1)
|
83
|
+
activesupport (>= 4.2.0, < 6.0)
|
84
|
+
nokogiri (~> 1.6.0)
|
85
|
+
rails-html-sanitizer (1.0.3)
|
86
|
+
loofah (~> 2.0)
|
87
|
+
railties (5.0.0.1)
|
88
|
+
actionpack (= 5.0.0.1)
|
89
|
+
activesupport (= 5.0.0.1)
|
90
|
+
method_source
|
91
|
+
rake (>= 0.8.7)
|
92
|
+
thor (>= 0.18.1, < 2.0)
|
93
|
+
rake (10.5.0)
|
94
|
+
sprockets (3.7.0)
|
95
|
+
concurrent-ruby (~> 1.0)
|
96
|
+
rack (> 1, < 3)
|
97
|
+
sprockets-rails (3.2.0)
|
98
|
+
actionpack (>= 4.0)
|
99
|
+
activesupport (>= 4.0)
|
100
|
+
sprockets (>= 3.0.0)
|
101
|
+
thor (0.19.1)
|
102
|
+
thread_safe (0.3.5)
|
103
|
+
tzinfo (1.2.2)
|
104
|
+
thread_safe (~> 0.1)
|
105
|
+
websocket-driver (0.6.4)
|
106
|
+
websocket-extensions (>= 0.1.0)
|
107
|
+
websocket-extensions (0.1.2)
|
108
|
+
|
109
|
+
PLATFORMS
|
110
|
+
ruby
|
111
|
+
|
112
|
+
DEPENDENCIES
|
113
|
+
bundler (~> 1.10)
|
114
|
+
camel_patrol!
|
115
|
+
minitest
|
116
|
+
rails (~> 5.0.0)
|
117
|
+
rake (~> 10.0)
|
118
|
+
|
119
|
+
BUNDLED WITH
|
120
|
+
1.13.6
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Bernardo Farah
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# CamelPatrol 🐪🚓
|
2
|
+
|
3
|
+
Inspired by [olive_branch](https://github.com/vigetlabs/olive_branch),
|
4
|
+
CamelPatrol is a middleware with a singular focus: Creating a border between 🐪 and 🐍.
|
5
|
+
|
6
|
+
In Ruby, we like to have `snake_case` variables, whereas using Javascript and
|
7
|
+
JSON, the convention is generally to use `camelCase`. This gem is the answer to
|
8
|
+
"Why not both?"
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'camel_patrol'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install camel_patrol
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
### Rails app
|
29
|
+
To use this in a normal rails application, you can add it to your application.rb
|
30
|
+
|
31
|
+
```rb
|
32
|
+
# config/application.rb
|
33
|
+
|
34
|
+
# Adds our middleware to the end of the stack
|
35
|
+
config.middleware.use CamelPatrol::Middleware
|
36
|
+
```
|
37
|
+
|
38
|
+
For more information from the official Rails docs, go
|
39
|
+
[here](http://guides.rubyonrails.org/rails_on_rack.html#configuring-middleware-stack)
|
40
|
+
|
41
|
+
|
42
|
+
### Rails engine
|
43
|
+
In order to add it to an engine, you'll want to add it in your engine file:
|
44
|
+
|
45
|
+
```rb
|
46
|
+
# my_engine/lib/engine.rb
|
47
|
+
|
48
|
+
# Adds our middleware to the end of the stack
|
49
|
+
config.middleware.use CamelPatrol::Middleware
|
50
|
+
```
|
51
|
+
|
52
|
+
## Development
|
53
|
+
|
54
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
55
|
+
|
56
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
57
|
+
|
58
|
+
## Contributing
|
59
|
+
|
60
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/coverhound/camel_patrol.
|
61
|
+
|
62
|
+
|
63
|
+
## License
|
64
|
+
|
65
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
66
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "camel_patrol"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'camel_patrol/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "camel_patrol"
|
8
|
+
spec.version = CamelPatrol::VERSION
|
9
|
+
spec.authors = ["Bernardo Farah"]
|
10
|
+
spec.email = ["bernardo@coverhound.com"]
|
11
|
+
|
12
|
+
spec.summary = "Middleware to transform camelCase into snake_case and back"
|
13
|
+
spec.description = "Middleware to transform camelCase into snake_case and back"
|
14
|
+
spec.homepage = "https://github.com/coverhound/camel_patrol"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test)/}) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "railties", ">= 4.1.0", "< 5.1"
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "minitest"
|
25
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git://github.com/rails/rails.git
|
3
|
+
revision: 6fab8c3de51448ca03ae5610c45111fa4635b75c
|
4
|
+
branch: 4-2-stable
|
5
|
+
specs:
|
6
|
+
actionmailer (4.2.7.1)
|
7
|
+
actionpack (= 4.2.7.1)
|
8
|
+
actionview (= 4.2.7.1)
|
9
|
+
activejob (= 4.2.7.1)
|
10
|
+
mail (~> 2.5, >= 2.5.4)
|
11
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
12
|
+
actionpack (4.2.7.1)
|
13
|
+
actionview (= 4.2.7.1)
|
14
|
+
activesupport (= 4.2.7.1)
|
15
|
+
rack (~> 1.6)
|
16
|
+
rack-test (~> 0.6.2)
|
17
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
18
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
19
|
+
actionview (4.2.7.1)
|
20
|
+
activesupport (= 4.2.7.1)
|
21
|
+
builder (~> 3.1)
|
22
|
+
erubis (~> 2.7.0)
|
23
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
24
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
25
|
+
activejob (4.2.7.1)
|
26
|
+
activesupport (= 4.2.7.1)
|
27
|
+
globalid (>= 0.3.0)
|
28
|
+
activemodel (4.2.7.1)
|
29
|
+
activesupport (= 4.2.7.1)
|
30
|
+
builder (~> 3.1)
|
31
|
+
activerecord (4.2.7.1)
|
32
|
+
activemodel (= 4.2.7.1)
|
33
|
+
activesupport (= 4.2.7.1)
|
34
|
+
arel (~> 6.0)
|
35
|
+
activesupport (4.2.7.1)
|
36
|
+
i18n (~> 0.7)
|
37
|
+
minitest (~> 5.1)
|
38
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
39
|
+
tzinfo (~> 1.1)
|
40
|
+
rails (4.2.7.1)
|
41
|
+
actionmailer (= 4.2.7.1)
|
42
|
+
actionpack (= 4.2.7.1)
|
43
|
+
actionview (= 4.2.7.1)
|
44
|
+
activejob (= 4.2.7.1)
|
45
|
+
activemodel (= 4.2.7.1)
|
46
|
+
activerecord (= 4.2.7.1)
|
47
|
+
activesupport (= 4.2.7.1)
|
48
|
+
bundler (>= 1.3.0, < 2.0)
|
49
|
+
railties (= 4.2.7.1)
|
50
|
+
sprockets-rails
|
51
|
+
railties (4.2.7.1)
|
52
|
+
actionpack (= 4.2.7.1)
|
53
|
+
activesupport (= 4.2.7.1)
|
54
|
+
rake (>= 0.8.7)
|
55
|
+
thor (>= 0.18.1, < 2.0)
|
56
|
+
|
57
|
+
PATH
|
58
|
+
remote: ..
|
59
|
+
specs:
|
60
|
+
camel_patrol (1.0.0)
|
61
|
+
railties (>= 4.1.0, < 5.1)
|
62
|
+
|
63
|
+
GEM
|
64
|
+
remote: https://rubygems.org/
|
65
|
+
specs:
|
66
|
+
arel (6.0.3)
|
67
|
+
builder (3.2.2)
|
68
|
+
concurrent-ruby (1.0.2)
|
69
|
+
erubis (2.7.0)
|
70
|
+
globalid (0.3.7)
|
71
|
+
activesupport (>= 4.1.0)
|
72
|
+
i18n (0.7.0)
|
73
|
+
loofah (2.0.3)
|
74
|
+
nokogiri (>= 1.5.9)
|
75
|
+
mail (2.6.4)
|
76
|
+
mime-types (>= 1.16, < 4)
|
77
|
+
mime-types (3.1)
|
78
|
+
mime-types-data (~> 3.2015)
|
79
|
+
mime-types-data (3.2016.0521)
|
80
|
+
mini_portile2 (2.1.0)
|
81
|
+
minitest (5.9.1)
|
82
|
+
nokogiri (1.6.8.1)
|
83
|
+
mini_portile2 (~> 2.1.0)
|
84
|
+
rack (1.6.5)
|
85
|
+
rack-test (0.6.3)
|
86
|
+
rack (>= 1.0)
|
87
|
+
rails-deprecated_sanitizer (1.0.3)
|
88
|
+
activesupport (>= 4.2.0.alpha)
|
89
|
+
rails-dom-testing (1.0.7)
|
90
|
+
activesupport (>= 4.2.0.beta, < 5.0)
|
91
|
+
nokogiri (~> 1.6.0)
|
92
|
+
rails-deprecated_sanitizer (>= 1.0.1)
|
93
|
+
rails-html-sanitizer (1.0.3)
|
94
|
+
loofah (~> 2.0)
|
95
|
+
rake (10.5.0)
|
96
|
+
sprockets (3.7.0)
|
97
|
+
concurrent-ruby (~> 1.0)
|
98
|
+
rack (> 1, < 3)
|
99
|
+
sprockets-rails (3.2.0)
|
100
|
+
actionpack (>= 4.0)
|
101
|
+
activesupport (>= 4.0)
|
102
|
+
sprockets (>= 3.0.0)
|
103
|
+
thor (0.19.1)
|
104
|
+
thread_safe (0.3.5)
|
105
|
+
tzinfo (1.2.2)
|
106
|
+
thread_safe (~> 0.1)
|
107
|
+
|
108
|
+
PLATFORMS
|
109
|
+
ruby
|
110
|
+
|
111
|
+
DEPENDENCIES
|
112
|
+
bundler (~> 1.10)
|
113
|
+
camel_patrol!
|
114
|
+
minitest
|
115
|
+
rails!
|
116
|
+
rake (~> 10.0)
|
117
|
+
|
118
|
+
BUNDLED WITH
|
119
|
+
1.13.6
|
data/lib/camel_patrol.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
module CamelPatrol
|
2
|
+
class Middleware
|
3
|
+
def initialize(app)
|
4
|
+
@app = app
|
5
|
+
end
|
6
|
+
|
7
|
+
def call(env)
|
8
|
+
underscore_params(env) if json?(env["CONTENT_TYPE"])
|
9
|
+
|
10
|
+
@app.call(env).tap do |_status, headers, response|
|
11
|
+
camelize_response(response) if json?(headers["Content-Type"])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def underscore_params(env)
|
18
|
+
if ::Rails::VERSION::MAJOR < 5
|
19
|
+
env["action_dispatch.request.request_parameters"].deep_transform_keys!(&:underscore)
|
20
|
+
else
|
21
|
+
request_body = JSON.parse(env["rack.input"].read)
|
22
|
+
request_body.deep_transform_keys!(&:underscore)
|
23
|
+
req = StringIO.new(request_body.to_json)
|
24
|
+
|
25
|
+
env["rack.input"] = req
|
26
|
+
env["CONTENT_LENGTH"] = req.length
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def camelize_response(response)
|
31
|
+
response.each do |body|
|
32
|
+
new_response = safe_json_parse(body) or next
|
33
|
+
new_response.deep_transform_keys! { |key| key.camelize(:lower) }
|
34
|
+
body.replace(new_response.to_json)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def safe_json_parse(body)
|
39
|
+
JSON.parse(body)
|
40
|
+
rescue JSON::ParserError
|
41
|
+
nil
|
42
|
+
end
|
43
|
+
|
44
|
+
def json?(content_type)
|
45
|
+
# WARNING:
|
46
|
+
# We"re using substring matching over Regexp intentionally - Middleware is a hot path and
|
47
|
+
# this will be checked on every request
|
48
|
+
content_type && content_type.include?("application/json")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: camel_patrol
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bernardo Farah
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: railties
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.1.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.1'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 4.1.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.1'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.10'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.10'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '10.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '10.0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: minitest
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
description: Middleware to transform camelCase into snake_case and back
|
76
|
+
email:
|
77
|
+
- bernardo@coverhound.com
|
78
|
+
executables: []
|
79
|
+
extensions: []
|
80
|
+
extra_rdoc_files: []
|
81
|
+
files:
|
82
|
+
- ".gitignore"
|
83
|
+
- ".rubocop.yml"
|
84
|
+
- ".travis.yml"
|
85
|
+
- Gemfile
|
86
|
+
- Gemfile.lock
|
87
|
+
- LICENSE.txt
|
88
|
+
- README.md
|
89
|
+
- Rakefile
|
90
|
+
- bin/console
|
91
|
+
- bin/setup
|
92
|
+
- camel_patrol.gemspec
|
93
|
+
- gemfiles/Gemfile.rails-4.2-stable
|
94
|
+
- gemfiles/Gemfile.rails-4.2-stable.lock
|
95
|
+
- lib/camel_patrol.rb
|
96
|
+
- lib/camel_patrol/middleware.rb
|
97
|
+
- lib/camel_patrol/version.rb
|
98
|
+
homepage: https://github.com/coverhound/camel_patrol
|
99
|
+
licenses:
|
100
|
+
- MIT
|
101
|
+
metadata: {}
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 2.5.1
|
119
|
+
signing_key:
|
120
|
+
specification_version: 4
|
121
|
+
summary: Middleware to transform camelCase into snake_case and back
|
122
|
+
test_files: []
|