case_transform 0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d3c8657db46167f5dedf62a6352b2633ed4648c3
4
+ data.tar.gz: 35bda195d78f3568e5b519ceb7c7e0c08f9dcd99
5
+ SHA512:
6
+ metadata.gz: 9fd74f7f2a60855bea9697b2c01e7d51164287f88321b659e796fa3809eb61c6777a5ae95149a9f8b721a20fcd965712c92eea97336fe4b4697d6626774cc582
7
+ data.tar.gz: 24b256717c863806d462c080af1795ae65a76038f0ec682755360798b229cec6f9d8c2561d6a832d2bbd109ee61e4d9550bb01a513cd909014d57bb7a399e489
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 L. Preston Sego III
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # key_transform
2
+ Extraction of the key_transform abilities of ActiveModelSerializers
3
+
4
+ ## Install
5
+
6
+ ```ruby
7
+ gem 'key_transform'
8
+ ```
9
+
10
+ or
11
+
12
+ ```ruby
13
+ require 'key_transform'
14
+ ```
15
+ ## Usage
16
+
17
+ ```ruby
18
+ CaseTransform.camel_lower(value)
19
+ ```
20
+
21
+ ### Transforms
22
+
23
+ |   | Description |
24
+ | --- | --- |
25
+ | camel | PascalCase |
26
+ | camel_lower | camelCase |
27
+ | dash | dash-case |
28
+ | underscore | under_score |
29
+ | unaltered | pass through |
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+ require 'active_support/core_ext/hash/keys'
3
+ require 'active_support/core_ext/string'
4
+
5
+ require 'case_transform/version'
6
+
7
+ module CaseTransform
8
+ module_function
9
+
10
+ # Transforms values to UpperCamelCase or PascalCase.
11
+ #
12
+ # @example:
13
+ # "some_key" => "SomeKey",
14
+ def camel(value)
15
+ case value
16
+ when Array then value.map { |item| camel(item) }
17
+ when Hash then value.deep_transform_keys! { |key| camel(key) }
18
+ when Symbol then camel(value.to_s).to_sym
19
+ when String then value.underscore.camelize
20
+ else value
21
+ end
22
+ end
23
+
24
+ # Transforms values to camelCase.
25
+ #
26
+ # @example:
27
+ # "some_key" => "someKey",
28
+ def camel_lower(value)
29
+ case value
30
+ when Array then value.map { |item| camel_lower(item) }
31
+ when Hash then value.deep_transform_keys! { |key| camel_lower(key) }
32
+ when Symbol then camel_lower(value.to_s).to_sym
33
+ when String then value.underscore.camelize(:lower)
34
+ else value
35
+ end
36
+ end
37
+
38
+ # Transforms values to dashed-case.
39
+ # This is the default case for the JsonApi adapter.
40
+ #
41
+ # @example:
42
+ # "some_key" => "some-key",
43
+ def dash(value)
44
+ case value
45
+ when Array then value.map { |item| dash(item) }
46
+ when Hash then value.deep_transform_keys! { |key| dash(key) }
47
+ when Symbol then dash(value.to_s).to_sym
48
+ when String then value.underscore.dasherize
49
+ else value
50
+ end
51
+ end
52
+
53
+ # Transforms values to underscore_case.
54
+ # This is the default case for deserialization in the JsonApi adapter.
55
+ #
56
+ # @example:
57
+ # "some-key" => "some_key",
58
+ def underscore(value)
59
+ case value
60
+ when Array then value.map { |item| underscore(item) }
61
+ when Hash then value.deep_transform_keys! { |key| underscore(key) }
62
+ when Symbol then underscore(value.to_s).to_sym
63
+ when String then value.underscore
64
+ else value
65
+ end
66
+ end
67
+
68
+ # Returns the value unaltered
69
+ def unaltered(value)
70
+ value
71
+ end
72
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+ module CaseTransform
3
+ VERSION = '0.1'.freeze
4
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: case_transform
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - L. Preston Sego III
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: codeclimate-test-reporter
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: awesome_print
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Extraction of the key_transform abilities of ActiveModelSerializers
98
+ email: LPSego3+dev@gmail.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - LICENSE
104
+ - README.md
105
+ - lib/case_transform.rb
106
+ - lib/case_transform/version.rb
107
+ homepage: https://github.com/NullVoxPopuli/case_transform
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '2.0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.5.1
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: CaseTransform-0.1
131
+ test_files: []