case_transform2 0.2 → 1.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: 045a1d213393c56a0fbc3d003bb3ecfc24113d70
4
- data.tar.gz: 0b19f7863b8ad5579d0c28124c361449f8817012
2
+ SHA256:
3
+ metadata.gz: 2508f1e130309a456cd3c7b57155fde46dd4bfb2da6a04d17763fa4e1b3b5625
4
+ data.tar.gz: d4ce5240085406f08ee747089147fe18d538eaf09f0a3252334787b74cffdd91
5
5
  SHA512:
6
- metadata.gz: 0beee36e50a3d77ba1c53b4e4a67de738969878ac2a30aa5cee3684cf8b341ba47714a04d5e83f91cb0c33c2fb7e61582af1bcc3b652ac47d6a7eec74cd96de5
7
- data.tar.gz: 9f1c45204c45b4deffce9903826cfa0e985ded1641fdf95a39d28165f9b9ca2e1420b15e4d4bacca1fd34e799141e014be64ed979261598129addc612a1e80d8
6
+ metadata.gz: 941332e0e0be855f72d31490ed0dc42a299cfaab150fde878ea6fee3c9c1b9c8145802df65b53cdc974f430bf4771c8ca46684b15cbd9cef9c44a8b16fd399bc
7
+ data.tar.gz: 2e69588e55a311133b5c5c9742d2293ad29df217d5c6ff93977bf465daac6ba90bf9e74dda339736518509df5e5e3e8c03b62ab6161333c973bd78153980a1a9
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ .rspec_status
1
2
  *.gem
2
3
  *.rbc
3
4
  /.config
data/.rspec CHANGED
@@ -1 +1,3 @@
1
+ --format documentation
2
+ --color
1
3
  --require spec_helper
data/.travis.yml CHANGED
@@ -1,3 +1,5 @@
1
+ sudo: false
2
+ before_install: gem install bundler -v 1.16.1
1
3
  env:
2
4
  global:
3
5
  - CC_TEST_REPORTER_ID=7eaf794e2ffbbd1bbe4eccd967a5428a6318cad2a33b8fd0baf42d6335a334a0
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at saiqulhaq@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile CHANGED
@@ -1,11 +1,6 @@
1
- # frozen_string_literal: true
2
-
3
1
  source "https://rubygems.org"
4
2
 
5
- # Specify your gem's dependencies in authorizable.gemspec
6
- gemspec
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
7
4
 
8
- group :development do
9
- gem "guard"
10
- gem "guard-rspec"
11
- end
5
+ # Specify your gem's dependencies in case_transform2.gemspec
6
+ gemspec
@@ -1,6 +1,7 @@
1
- MIT License
1
+ The MIT License (MIT)
2
2
 
3
3
  Copyright (c) 2016 L. Preston Sego III
4
+ Copyright (c) 2018 M. Saiqul Haq
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  of this software and associated documentation files (the "Software"), to deal
@@ -9,13 +10,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
10
  copies of the Software, and to permit persons to whom the Software is
10
11
  furnished to do so, subject to the following conditions:
11
12
 
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
14
15
 
15
16
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
17
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
18
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
19
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
20
  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.
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
data/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  + [case_transform2](#case_transform2)
4
4
  * [Why](#why)
5
5
  * [Install](#install)
6
+ * [Warning](#warning)
6
7
  * [Usage](#usage)
7
8
  * [Transforms](#transforms)
8
9
  * [NOTE](#note)
@@ -37,22 +38,27 @@ or
37
38
  gem install case_transform2
38
39
  ```
39
40
 
41
+ ## Warning
42
+
43
+ if you use 0.x version and want to upgrade to newest version
44
+ you *must* rename all CaseTransform to be CaseTransform2
45
+
40
46
  ## Usage
41
47
 
42
48
  ```ruby
43
49
  require 'case_transform2'
44
50
 
45
51
  value = "hello_world"
46
- CaseTransform.camel_lower(value) # => helloWorld
52
+ CaseTransform2.camel_lower(value) # => helloWorld
47
53
 
48
54
  value = "hello_world"
49
- CaseTransform.camel(value) # => HelloWorld
55
+ CaseTransform2.camel(value) # => HelloWorld
50
56
 
51
57
  value = "hello_world"
52
- CaseTransform.dash(value) # => hello-world
58
+ CaseTransform2.dash(value) # => hello-world
53
59
 
54
60
  value = "helloWorld"
55
- CaseTransform.underscore(value) # => hello_world
61
+ CaseTransform2.underscore(value) # => hello_world
56
62
  ```
57
63
 
58
64
  `value` can be any of Array, Hash, Symbol, or String.
@@ -69,6 +75,6 @@ Any other object type will just be returned.
69
75
 
70
76
  ## NOTE
71
77
 
72
- There is no `CaseTransform.unaltered` method like the original gem has
78
+ There is no `CaseTransform2.unaltered` method like the original gem has
73
79
 
74
- License MIT
80
+ License: See LICENSE.txt file
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "case_transform2"
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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -2,11 +2,11 @@
2
2
 
3
3
  lib = File.expand_path("lib", __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require "case_transform/version"
5
+ require "case_transform2/version"
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "case_transform2"
9
- s.version = CaseTransform::VERSION
9
+ s.version = CaseTransform2::VERSION
10
10
  s.license = "MIT"
11
11
  s.authors = ["L. Preston Sego III", "Ben Mills", "Saiqul Haq"]
12
12
  s.email = "saiqulhaq@gmail.com"
@@ -24,6 +24,7 @@ Gem::Specification.new do |s|
24
24
 
25
25
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
26
26
 
27
+ s.add_development_dependency "bundler", "~> 1.16"
27
28
  s.add_development_dependency "pry", "~> 0.10.4"
28
29
  s.add_development_dependency "rake", "~> 11.2.2"
29
30
  s.add_development_dependency "rspec", "~> 3.7.0"
@@ -1,2 +1,111 @@
1
- require "case_transform"
2
- module CaseTransform2; end
1
+ # frozen_string_literal: true
2
+
3
+ require "case_transform2/hash_ext"
4
+ require "case_transform2/string_ext"
5
+ require "case_transform2/version"
6
+
7
+ module CaseTransform2
8
+ class << self
9
+ # Transforms values to UpperCamelCase or PascalCase.
10
+ #
11
+ # @example
12
+ # "some_key" => "SomeKey",
13
+ def camel(value)
14
+ case value
15
+ when Array
16
+ value.map { |item| camel(item) }
17
+ when Hash
18
+ hash_ext.deep_transform_keys!(value) { |key| camel(key) }
19
+ when Symbol
20
+ camel(value.to_s).to_sym
21
+ when String
22
+ camel_cache[value] ||= string_ext.camelize(string_ext.underscore(value))
23
+ else
24
+ value
25
+ end
26
+ end
27
+
28
+ # Transforms values to camelCase.
29
+ #
30
+ # @example
31
+ # "some_key" => "someKey",
32
+ def camel_lower(value)
33
+ case value
34
+ when Array
35
+ value.map { |item| camel_lower(item) }
36
+ when Hash
37
+ hash_ext.deep_transform_keys!(value) { |key| camel_lower(key) }
38
+ when Symbol
39
+ camel_lower(value.to_s).to_sym
40
+ when String
41
+ camel_lower_cache[value] ||= string_ext.camelize(string_ext.underscore(value), :lower)
42
+ else
43
+ value
44
+ end
45
+ end
46
+
47
+ # Transforms values to dashed-case.
48
+ #
49
+ # @example
50
+ # "some_key" => "some-key",
51
+ def dash(value)
52
+ case value
53
+ when Array
54
+ value.map { |item| dash(item) }
55
+ when Hash
56
+ hash_ext.deep_transform_keys!(value) { |key| dash(key) }
57
+ when Symbol
58
+ dash(value.to_s).to_sym
59
+ when String
60
+ dash_cache[value] ||= string_ext.dasherize(string_ext.underscore(value))
61
+ else
62
+ value
63
+ end
64
+ end
65
+
66
+ # Transforms values to underscore_case.
67
+ #
68
+ # @example
69
+ # "some-key" => "some_key",
70
+ def underscore(value)
71
+ case value
72
+ when Array
73
+ value.map { |item| underscore(item) }
74
+ when Hash
75
+ hash_ext.deep_transform_keys!(value) { |key| underscore(key) }
76
+ when Symbol
77
+ underscore(value.to_s).to_sym
78
+ when String
79
+ underscore_cache[value] ||= string_ext.underscore(value)
80
+ else
81
+ value
82
+ end
83
+ end
84
+
85
+ private
86
+
87
+ def string_ext
88
+ @string_ext ||= CaseTransform2::StringExt.new
89
+ end
90
+
91
+ def hash_ext
92
+ @hash_ext ||= CaseTransform2::HashExt.new
93
+ end
94
+
95
+ def camel_cache
96
+ @camel_cache ||= {}
97
+ end
98
+
99
+ def camel_lower_cache
100
+ @camel_lower_cache ||= {}
101
+ end
102
+
103
+ def dash_cache
104
+ @dash_cache ||= {}
105
+ end
106
+
107
+ def underscore_cache
108
+ @underscore_cache ||= {}
109
+ end
110
+ end
111
+ end
@@ -1,4 +1,7 @@
1
- module CaseTransform
1
+ # frozen_string_literal: true
2
+
3
+ module CaseTransform2
4
+ # @api private
2
5
  class HashExt
3
6
  def deep_transform_keys!(object, &block)
4
7
  _deep_transform_keys_in_object!(object, &block)
@@ -1,8 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module CaseTransform
3
+ module CaseTransform2
4
4
  # String class extension
5
5
  # Stolen from ActiveSupport::Inflector.camelize
6
+ # @api private
6
7
  class StringExt
7
8
  def camelize(string, first_letter = :upper)
8
9
  raise ArgumentError, "Argument can not be nil" unless %i[upper lower].include?(first_letter)
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CaseTransform2
4
+ VERSION = "1.0.0".freeze
5
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: case_transform2
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - L. Preston Sego III
@@ -10,8 +10,22 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2018-05-06 00:00:00.000000000 Z
13
+ date: 2018-07-05 00:00:00.000000000 Z
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '1.16'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '1.16'
15
29
  - !ruby/object:Gem::Dependency
16
30
  name: pry
17
31
  requirement: !ruby/object:Gem::Requirement
@@ -80,18 +94,20 @@ files:
80
94
  - ".rspec"
81
95
  - ".rubocop.yml"
82
96
  - ".travis.yml"
97
+ - CODE_OF_CONDUCT.md
83
98
  - Gemfile
84
99
  - Gemfile.lock
85
100
  - Guardfile
86
- - LICENSE
101
+ - LICENSE.txt
87
102
  - README.md
88
103
  - Rakefile
89
- - case_transform.gemspec
90
- - lib/case_transform.rb
91
- - lib/case_transform/hash_ext.rb
92
- - lib/case_transform/string_ext.rb
93
- - lib/case_transform/version.rb
104
+ - bin/console
105
+ - bin/setup
106
+ - case_transform2.gemspec
94
107
  - lib/case_transform2.rb
108
+ - lib/case_transform2/hash_ext.rb
109
+ - lib/case_transform2/string_ext.rb
110
+ - lib/case_transform2/version.rb
95
111
  homepage: https://github.com/saiqulhaq/case_transform
96
112
  licenses:
97
113
  - MIT
@@ -113,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
129
  version: '0'
114
130
  requirements: []
115
131
  rubyforge_project:
116
- rubygems_version: 2.5.2
132
+ rubygems_version: 2.7.3
117
133
  signing_key:
118
134
  specification_version: 4
119
135
  summary: Transforms string letter case to camel, snake, dash and underscore without
@@ -1,112 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'case_transform/hash_ext'
3
- require 'case_transform/string_ext'
4
- require 'case_transform/version'
5
-
6
- module CaseTransform
7
- class << self
8
- def camel_cache
9
- @camel_cache ||= {}
10
- end
11
-
12
- def camel_lower_cache
13
- @camel_lower_cache ||= {}
14
- end
15
-
16
- def dash_cache
17
- @dash_cache ||= {}
18
- end
19
-
20
- def underscore_cache
21
- @underscore_cache ||= {}
22
- end
23
-
24
- # Transforms values to UpperCamelCase or PascalCase.
25
- #
26
- # @example:
27
- # "some_key" => "SomeKey",
28
- def camel(value)
29
- case value
30
- when Array
31
- value.map { |item| camel(item) }
32
- when Hash
33
- hash_ext.deep_transform_keys!(value) { |key| camel(key) }
34
- when Symbol
35
- camel(value.to_s).to_sym
36
- when String
37
- camel_cache[value] ||= string_ext.camelize(string_ext.underscore(value))
38
- else
39
- value
40
- end
41
- end
42
-
43
- # Transforms values to camelCase.
44
- #
45
- # @example:
46
- # "some_key" => "someKey",
47
- def camel_lower(value)
48
- case value
49
- when Array
50
- value.map { |item| camel_lower(item) }
51
- when Hash
52
- hash_ext.deep_transform_keys!(value) { |key| camel_lower(key) }
53
- when Symbol
54
- camel_lower(value.to_s).to_sym
55
- when String
56
- camel_lower_cache[value] ||= string_ext.camelize(string_ext.underscore(value), :lower)
57
- else
58
- value
59
- end
60
- end
61
-
62
- # Transforms values to dashed-case.
63
- # This is the default case for the JsonApi adapter.
64
- #
65
- # @example:
66
- # "some_key" => "some-key",
67
- def dash(value)
68
- case value
69
- when Array
70
- value.map { |item| dash(item) }
71
- when Hash
72
- hash_ext.deep_transform_keys!(value) { |key| dash(key) }
73
- when Symbol
74
- dash(value.to_s).to_sym
75
- when String
76
- dash_cache[value] ||= string_ext.dasherize(string_ext.underscore(value))
77
- else
78
- value
79
- end
80
- end
81
-
82
- # Transforms values to underscore_case.
83
- # This is the default case for deserialization in the JsonApi adapter.
84
- #
85
- # @example:
86
- # "some-key" => "some_key",
87
- def underscore(value)
88
- case value
89
- when Array
90
- value.map { |item| underscore(item) }
91
- when Hash
92
- hash_ext.deep_transform_keys!(value) { |key| underscore(key) }
93
- when Symbol
94
- underscore(value.to_s).to_sym
95
- when String
96
- underscore_cache[value] ||= string_ext.underscore(value)
97
- else
98
- value
99
- end
100
- end
101
-
102
- private
103
-
104
- def string_ext
105
- @string_ext ||= CaseTransform::StringExt.new
106
- end
107
-
108
- def hash_ext
109
- @hash_ext ||= CaseTransform::HashExt.new
110
- end
111
- end
112
- end
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
- module CaseTransform
3
- VERSION = '0.2'.freeze
4
- end