underscorize_params 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9a95c1ee6a64560aeb76607c11bdd0e5bdd1d27ee2bc801c23480524654186b6
4
+ data.tar.gz: d8cd0b84a8da8122a48ac2a575347f6dde48a792d6c7e4d663928066c6c3960a
5
+ SHA512:
6
+ metadata.gz: 89533b0533dda7743c57fe603c0c259a1269a3a8fcbf8bf4cb17ae2da78fb120d70ec3486d317593f0d5fabf2d95e234cd165d0a690cf7b9c7bf584acd625ff3
7
+ data.tar.gz: eeb9bdb94d3006b6a0ad5161ec189a28ae1b65b12191a19d76339db4e99e7cc230220eaeb95443f266e69457532a25fb76e9bbc74a6d4319672a208f234879fd
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'action_controller'
4
+
5
+ module UnderscorizeParams
6
+ module Controller
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ before_action :underscore_params!
11
+ end
12
+
13
+ private
14
+
15
+ def underscore_params!
16
+ params.instance_variable_get(:@parameters).deep_transform_keys!(&:underscore)
17
+ end
18
+ end
19
+ end
20
+
21
+ ActionController::Base.include UnderscorizeParams::Controller if defined?(ActionController::Base)
@@ -0,0 +1,3 @@
1
+ module UnderscorizeParams
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UnderscorizeParams
4
+ end
5
+
6
+ require 'underscorize_params/controller'
@@ -0,0 +1,11 @@
1
+ require 'action_controller'
2
+ require 'rspec'
3
+ require 'underscorize_params'
4
+
5
+ I18n.enforce_available_locales = false
6
+ RSpec::Expectations.configuration.warn_about_potential_false_positives = false
7
+
8
+ Dir[File.expand_path('support/*.rb', __dir__)].each { |f| require f }
9
+
10
+ RSpec.configure do |config|
11
+ end
@@ -0,0 +1,4 @@
1
+ class PeopleController < ActionController::Base
2
+ def create
3
+ end
4
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe PeopleController, type: :controller do
4
+ let(:params_hash) do
5
+ {
6
+ userId: 1,
7
+ firstName: 'John',
8
+ lastName: 'Doe'
9
+ }
10
+ end
11
+
12
+ let(:params) do
13
+ ActionController::Parameters.new(params_hash)
14
+ end
15
+
16
+ it 'should correctly underscorize all params' do
17
+ allow_any_instance_of(described_class).to receive(:params).and_return(params)
18
+ subject.send :underscore_params!
19
+
20
+ expect(params[:user_id]).to eq(1)
21
+ expect(params[:first_name]).to eq('John')
22
+ expect(params[:last_name]).to eq('Doe')
23
+
24
+ expect(params[:userId]).to be(nil)
25
+ expect(params[:firstName]).to be(nil)
26
+ expect(params[:lastName]).to be(nil)
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: underscorize_params
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Mònade
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-05-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: actionpack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '8'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '5'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '8'
33
+ - !ruby/object:Gem::Dependency
34
+ name: activesupport
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '5'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '8'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '5'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '8'
53
+ - !ruby/object:Gem::Dependency
54
+ name: rspec
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '3'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '3'
67
+ - !ruby/object:Gem::Dependency
68
+ name: rubocop
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ description: Underscorize params
82
+ email: team@monade.io
83
+ executables: []
84
+ extensions: []
85
+ extra_rdoc_files: []
86
+ files:
87
+ - lib/underscorize_params.rb
88
+ - lib/underscorize_params/controller.rb
89
+ - lib/underscorize_params/version.rb
90
+ - spec/spec_helper.rb
91
+ - spec/support/controller.rb
92
+ - spec/underscorize_params/controller_spec.rb
93
+ homepage: https://rubygems.org/gems/underscorize_params
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: 2.7.0
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubygems_version: 3.2.33
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Underscorize params
116
+ test_files:
117
+ - spec/spec_helper.rb
118
+ - spec/support/controller.rb
119
+ - spec/underscorize_params/controller_spec.rb