snaky_params 2.2.0 → 3.0.0

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
- SHA1:
3
- metadata.gz: 90fd08630e3dd80d107f27ab601e0ced1e730772
4
- data.tar.gz: 357d8d26c1be9b8778844315664861449118abc6
2
+ SHA256:
3
+ metadata.gz: 3229a8f06396d4406b28d9602e913f471aee51421bdd4302dc6b4dfd707c6d91
4
+ data.tar.gz: d9c6e2722572559595d24296ee79764f133521e7f7b69f524d14656be7ceb653
5
5
  SHA512:
6
- metadata.gz: c9c42058528894b19d1e9647fb652cce4bf5322cb5e0b43c10b7ad696e3cbe9047522a5520d2bbd01670e53c8974443e776cec390eb6d82611d99c6745724ba8
7
- data.tar.gz: 53234e1067650e8b40f44b4d1b4285e2365c5cb1e3e543ea689f473b8091e79ff628394d1518f3ea252053cd03dac8946cb9ee550da249ac76cc4b5e38f211c4
6
+ metadata.gz: 1d0fef0e2d5733dc53df4dade9aca0cadc6ced1232e892fbfd4b78f4277e816523173ffb60930d58afd4cd93312b0e8d5366e5593b007f5da2f6df33fb1efd0f
7
+ data.tar.gz: f005bc29b3b62c9f3f4a2010dd160c0af270c4550f593789454a13c85c7c45b1f79f27c6470080f332fc2586539e496ce9540c671a473ab6379755f413ba4d00
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # SnakyParams
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/snaky_params.svg)](https://badge.fury.io/rb/snaky_params)
4
+
3
5
  SnakyParams is Rack middleware for Rails that automatically converts request parameter keys to snake_case.
4
6
 
5
- This is useful if you Rails app is being used as an API for a JavaScript frontend. In Ruby and Rails, the widely adopted naming convention is to use `snake_case` for variables, keys etc. Popular JavaScript style guides (such as the [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript)) tend to recommend camelCase. This gem allows you to use snake_case in all Ruby/Rails code and camelCase in JavaScript code without having to worry about converting the case of parameter names or having non-conventional names.
7
+ This is useful if you Rails app is being used as an API for a front-end application written in any other language (e.g. JavaScript). In Ruby and Rails, the widely adopted naming convention is to use `snake_case` for variables, keys etc. Popular JavaScript style guides (such as the [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript)) tend to recommend camelCase. This gem allows you to use snake_case in all Ruby/Rails code without having to worry about converting the case of parameter names or having non-conventional names.
6
8
 
7
9
  ## Installation
8
10
 
@@ -20,11 +22,13 @@ config.middleware.use SnakyParams::Middleware
20
22
 
21
23
  ## Usage
22
24
 
23
- Conversion is automatic. All parameter keys in requests to your Rails application are converted to snake_case.
24
-
25
- Example:
25
+ Conversion is automatic. All query, post, put and patch parameter keys in requests to your Rails application are converted to snake_case.
26
26
 
27
- - Your application receives a request to `yourapp.com/search?searchQuery=cobra`. In the `params` hash in your Rails controller, the param key name will be `search_query`.
27
+ Example:
28
+ - `searchQuery` becomes `search_query`
29
+ - `FirstName` becomes `first_name`
30
+ - `last-name` becomes `last_name`
31
+ - `monthlyOrYearlySalary` becomes `monthly_or_yearly_salary`
28
32
 
29
33
 
30
34
  ## Contributing
@@ -5,13 +5,12 @@ module SnakyParams
5
5
  end
6
6
 
7
7
  def call(env)
8
- # Transforming request
9
- request = Rack::Request.new(env)
8
+ request = ActionDispatch::Request.new(env)
10
9
 
11
- request.GET.deep_transform_keys!(&:underscore)
12
- request.POST.deep_transform_keys!(&:underscore)
10
+ request.request_parameters.deep_transform_keys!(&:underscore)
11
+ request.query_parameters.deep_transform_keys!(&:underscore)
13
12
 
14
13
  @app.call(env)
15
14
  end
16
15
  end
17
- end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module SnakyParams
2
- VERSION = "2.2.0"
2
+ VERSION = "3.0.0"
3
3
  end
data/snaky_params.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
23
 
24
- spec.add_dependency "rails", ">= 4.0"
24
+ spec.add_dependency "rails", ">= 5.0"
25
25
 
26
26
  spec.add_development_dependency "bundler", "~> 1.15"
27
27
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snaky_params
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Usman Sherwani
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-29 00:00:00.000000000 Z
11
+ date: 2018-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.0'
19
+ version: '5.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '4.0'
26
+ version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  version: '0'
91
91
  requirements: []
92
92
  rubyforge_project:
93
- rubygems_version: 2.6.11
93
+ rubygems_version: 2.7.6
94
94
  signing_key:
95
95
  specification_version: 4
96
96
  summary: Middleware to convert params to snake_case