param_keys_conv 0.1.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: 80c46304976e9eeb5e8899b1f9f40b7760d909a7f99cb89d741c9030402eaa29
4
+ data.tar.gz: 76cf7e48eb81a04a673b26dd6f9075d15afcd7a19275f931450e8d459afd39e0
5
+ SHA512:
6
+ metadata.gz: 2877e92fcb1bccd2dc2512562bf81ad0dffafa4a69f7d7b8b36914ea0e0ebcd7c0196150637f86b5a43340312a5fe126cc7c5255fec4383ba94904f641d6a144
7
+ data.tar.gz: 5e3baa07ba406d3177c6c070eb81194d9dc6f63151e0c2c876a0bc5d789fae0ab4b315220f980266e6fe7e41963e7e25cf0d2a7aba18813ce1f8457f821de6a2
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2020 tabakazu
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # param_keys_conv
2
+ param_keys_conv is keys converter of strong parameters.
3
+
4
+ ## Usage
5
+ ```ruby
6
+ # Convert camelCase to under_score.
7
+ params # => <ActionController::Parameters {"user"=>{"nickName"=>"Alice", "userRole"=>"admin"}} permitted: false>
8
+ params.underscore_keys # => <ActionController::Parameters {"user"=>{"nick_name"=>"Alice", "user_role"=>"admin"}} permitted: false>
9
+
10
+ # Convert under_score to camelCase.
11
+ params # => <ActionController::Parameters {"user"=>{"nick_name"=>"Alice", "user_role"=>"admin"}} permitted: false>
12
+ params.camelize_keys(:lower) # => <ActionController::Parameters {"user"=>{"nickName"=>"Alice", "userRole"=>"admin"}} permitted: false>
13
+ ```
14
+
15
+ ## Installation
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'param_keys_conv'
20
+ ```
21
+
22
+ And then execute:
23
+ ```bash
24
+ $ bundle
25
+ ```
26
+
27
+ Or install it yourself as:
28
+ ```bash
29
+ $ gem install param_keys_conv
30
+ ```
31
+
32
+ ## Contributing
33
+ Contribution directions go here.
34
+
35
+ ## License
36
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'ParamKeysConv'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ require 'bundler/gem_tasks'
18
+
19
+ require 'rake/testtask'
20
+
21
+ Rake::TestTask.new(:test) do |t|
22
+ t.libs << 'test'
23
+ t.pattern = 'test/**/*_test.rb'
24
+ t.verbose = false
25
+ end
26
+
27
+ task default: :test
@@ -0,0 +1,26 @@
1
+ module ActionController
2
+ class Parameters
3
+ # Example:
4
+ # params = ActionController::Parameters.new(user: { nickName: "Francesco", age: 22, userRole: "admin" })
5
+ # params.underscore_keys # => <ActionController::Parameters {"user"=>{"nick_name"=>"Francesco", "age"=>22, "user_role"=>"admin"}} permitted: false>
6
+ def underscore_keys
7
+ self.class.new(@parameters.deep_transform_keys { |key| key.to_s.underscore })
8
+ end
9
+
10
+ def underscore_keys!
11
+ @parameters.deep_transform_keys! { |key| key.to_s.underscore }
12
+ end
13
+
14
+ # Example:
15
+ # params = ActionController::Parameters.new(user: { nick_name: "Francesco", age: 22, user_role: "admin" })
16
+ # params.camelize_keys # => <ActionController::Parameters {"User"=>{"NickName"=>"Francesco", "Age"=>22, "UserRole"=>"admin"}} permitted: false>
17
+ # params.camelize_keys(:lower) # => <ActionController::Parameters {"user"=>{"nickName"=>"Francesco", "age"=>22, "userRole"=>"admin"}} permitted: false>
18
+ def camelize_keys(first_letter = :upper)
19
+ self.class.new(@parameters.deep_transform_keys { |key| key.to_s.camelize(first_letter) })
20
+ end
21
+
22
+ def camelize_keys!(first_letter = :upper)
23
+ @parameters.deep_transform_keys! { |key| key.to_s.camelize(first_letter) }
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,6 @@
1
+ require 'action_controller/parameters'
2
+ require 'param_keys_conv/railtie'
3
+
4
+ module ParamKeysConv
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,4 @@
1
+ module ParamKeysConv
2
+ class Railtie < ::Rails::Railtie
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module ParamKeysConv
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :param_keys_conv do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: param_keys_conv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - tabakazu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-02-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 6.0.2
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 6.0.2.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 6.0.2
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 6.0.2.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: sqlite3
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ description: Add string case converter to Ruby on Rails strong parameter keys.
48
+ email:
49
+ - tkazz.bd1@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - MIT-LICENSE
55
+ - README.md
56
+ - Rakefile
57
+ - lib/action_controller/parameters.rb
58
+ - lib/param_keys_conv.rb
59
+ - lib/param_keys_conv/railtie.rb
60
+ - lib/param_keys_conv/version.rb
61
+ - lib/tasks/param_keys_conv_tasks.rake
62
+ homepage: https://github.com/tabakazu
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubygems_version: 3.0.3
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Strong parameter keys converter.
85
+ test_files: []