case_transform2 0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 045a1d213393c56a0fbc3d003bb3ecfc24113d70
4
+ data.tar.gz: 0b19f7863b8ad5579d0c28124c361449f8817012
5
+ SHA512:
6
+ metadata.gz: 0beee36e50a3d77ba1c53b4e4a67de738969878ac2a30aa5cee3684cf8b341ba47714a04d5e83f91cb0c33c2fb7e61582af1bcc3b652ac47d6a7eec74cd96de5
7
+ data.tar.gz: 9f1c45204c45b4deffce9903826cfa0e985ded1641fdf95a39d28165f9b9ca2e1420b15e4d4bacca1fd34e799141e014be64ed979261598129addc612a1e80d8
@@ -0,0 +1,50 @@
1
+ # This is a sample .codeclimate.yml configured for Engine analysis on Code
2
+ # Climate Platform. For an overview of the Code Climate Platform, see here:
3
+ # http://docs.codeclimate.com/article/300-the-codeclimate-platform
4
+
5
+ # Under the engines key, you can configure which engines will analyze your repo.
6
+ # Each key is an engine name. For each value, you need to specify enabled: true
7
+ # to enable the engine as well as any other engines-specific configuration.
8
+
9
+ # For more details, see here:
10
+ # http://docs.codeclimate.com/article/289-configuring-your-repository-via-codeclimate-yml#platform
11
+
12
+ # For a list of all available engines, see here:
13
+ # http://docs.codeclimate.com/article/296-engines-available-engines
14
+
15
+ engines:
16
+ # to turn on an engine, add it here and set enabled to `true`
17
+ # to turn off an engine, set enabled to `false` or remove it
18
+ rubocop:
19
+ enabled: true
20
+ # golint:
21
+ # enabled: true
22
+ # gofmt:
23
+ # enabled: true
24
+ # eslint:
25
+ # enabled: true
26
+ # csslint:
27
+ # enabled: true
28
+
29
+ # Engines can analyze files and report issues on them, but you can separately
30
+ # decide which files will receive ratings based on those issues. This is
31
+ # specified by path patterns under the ratings key.
32
+
33
+ # For more details see here:
34
+ # http://docs.codeclimate.com/article/289-configuring-your-repository-via-codeclimate-yml#platform
35
+
36
+ # Note: If the ratings key is not specified, this will result in a 0.0 GPA on your dashboard.
37
+
38
+ ratings:
39
+ paths:
40
+ - lib/**
41
+ # - app/**
42
+ # - "**.rb"
43
+ # - "**.go"
44
+
45
+ # You can globally exclude files from being analyzed by any engine using the
46
+ # exclude_paths key.
47
+
48
+ exclude_paths:
49
+ - spec/**/*
50
+ - vendor/**/*
@@ -0,0 +1,50 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ Gemfile.lock
46
+ .ruby-version
47
+ .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
@@ -0,0 +1,146 @@
1
+ Metrics/BlockLength:
2
+ Exclude:
3
+ - 'Rakefile'
4
+ - '**/*.rake'
5
+ - 'spec/**/*.rb'
6
+
7
+ # Prefer &&/|| over and/or.
8
+ Style/AndOr:
9
+ Enabled: true
10
+
11
+ # Do not use braces for hash literals when they are the last argument of a
12
+ # method call.
13
+ Style/BracesAroundHashParameters:
14
+ Enabled: true
15
+ EnforcedStyle: context_dependent
16
+
17
+ # Align `when` with `case`.
18
+ Layout/CaseIndentation:
19
+ Enabled: true
20
+
21
+ # Align comments with method definitions.
22
+ Layout/CommentIndentation:
23
+ Enabled: true
24
+
25
+ Layout/ElseAlignment:
26
+ Enabled: true
27
+
28
+ # Align `end` with the matching keyword or starting expression except for
29
+ # assignments, where it should be aligned with the LHS.
30
+ Layout/EndAlignment:
31
+ Enabled: true
32
+ EnforcedStyleAlignWith: variable
33
+ AutoCorrect: true
34
+
35
+ Layout/EmptyLineAfterMagicComment:
36
+ Enabled: true
37
+
38
+ # In a regular class definition, no empty lines around the body.
39
+ Layout/EmptyLinesAroundClassBody:
40
+ Enabled: true
41
+
42
+ # In a regular method definition, no empty lines around the body.
43
+ Layout/EmptyLinesAroundMethodBody:
44
+ Enabled: true
45
+
46
+ # In a regular module definition, no empty lines around the body.
47
+ Layout/EmptyLinesAroundModuleBody:
48
+ Enabled: true
49
+
50
+ Layout/FirstParameterIndentation:
51
+ Enabled: true
52
+
53
+ # Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
54
+ Style/HashSyntax:
55
+ Enabled: true
56
+
57
+ # Two spaces, no tabs (for indentation).
58
+ Layout/IndentationWidth:
59
+ Enabled: true
60
+
61
+ Layout/LeadingCommentSpace:
62
+ Enabled: true
63
+
64
+ Layout/SpaceAfterColon:
65
+ Enabled: true
66
+
67
+ Layout/SpaceAfterComma:
68
+ Enabled: true
69
+
70
+ Layout/SpaceAroundEqualsInParameterDefault:
71
+ Enabled: true
72
+
73
+ Layout/SpaceAroundKeyword:
74
+ Enabled: true
75
+
76
+ Layout/SpaceAroundOperators:
77
+ Enabled: true
78
+
79
+ Layout/SpaceBeforeComma:
80
+ Enabled: true
81
+
82
+ Layout/SpaceBeforeFirstArg:
83
+ Enabled: true
84
+
85
+ Style/DefWithParentheses:
86
+ Enabled: true
87
+
88
+ # Defining a method with parameters needs parentheses.
89
+ Style/MethodDefParentheses:
90
+ Enabled: true
91
+
92
+ Style/FrozenStringLiteralComment:
93
+ Enabled: true
94
+ EnforcedStyle: always
95
+
96
+ # Use `foo {}` not `foo{}`.
97
+ Layout/SpaceBeforeBlockBraces:
98
+ Enabled: true
99
+
100
+ # Use `foo { bar }` not `foo {bar}`.
101
+ Layout/SpaceInsideBlockBraces:
102
+ Enabled: true
103
+
104
+ # Use `{ a: 1 }` not `{a:1}`.
105
+ Layout/SpaceInsideHashLiteralBraces:
106
+ Enabled: true
107
+
108
+ Layout/SpaceInsideParens:
109
+ Enabled: true
110
+
111
+ # Check quotes usage according to lint rule below.
112
+ Style/StringLiterals:
113
+ Enabled: true
114
+ EnforcedStyle: double_quotes
115
+
116
+ # Detect hard tabs, no hard tabs.
117
+ Layout/Tab:
118
+ Enabled: true
119
+
120
+ # Blank lines should not have any spaces.
121
+ Layout/TrailingBlankLines:
122
+ Enabled: true
123
+
124
+ # No trailing whitespace.
125
+ Layout/TrailingWhitespace:
126
+ Enabled: true
127
+
128
+ # Use quotes for string literals when they are enough.
129
+ Style/UnneededPercentQ:
130
+ Enabled: true
131
+
132
+ # Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
133
+ Lint/RequireParentheses:
134
+ Enabled: true
135
+
136
+ Style/RedundantReturn:
137
+ Enabled: true
138
+ AllowMultipleReturnValues: true
139
+
140
+ Style/Semicolon:
141
+ Enabled: true
142
+ AllowAsExpressionSeparator: true
143
+
144
+ # Prefer Foo.method over Foo::method
145
+ Style/ColonMethodCall:
146
+ Enabled: true
@@ -0,0 +1,27 @@
1
+ env:
2
+ global:
3
+ - CC_TEST_REPORTER_ID=7eaf794e2ffbbd1bbe4eccd967a5428a6318cad2a33b8fd0baf42d6335a334a0
4
+ language: ruby
5
+ bundler_args: --without guard guard-rspec
6
+ rvm:
7
+ - "2.3.7"
8
+ - "2.4.4"
9
+ - "2.5.1"
10
+ - ruby-head
11
+ branches:
12
+ only: master
13
+ notifications:
14
+ email: false
15
+ matrix:
16
+ fast_finish: true
17
+ allow_failures:
18
+ - rvm: ruby-head
19
+
20
+ before_script:
21
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
22
+ - chmod +x ./cc-test-reporter
23
+ - ./cc-test-reporter before-build
24
+ script:
25
+ - COVERAGE=1 bundle exec rspec
26
+ after_script:
27
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in authorizable.gemspec
6
+ gemspec
7
+
8
+ group :development do
9
+ gem "guard"
10
+ gem "guard-rspec"
11
+ end
@@ -0,0 +1,70 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
25
+ # * 'just' rspec: 'rspec'
26
+
27
+ guard :rspec, cmd: "bundle exec rspec" do
28
+ require "guard/rspec/dsl"
29
+ dsl = Guard::RSpec::Dsl.new(self)
30
+
31
+ # Feel free to open issues for suggestions and improvements
32
+
33
+ # RSpec files
34
+ rspec = dsl.rspec
35
+ watch(rspec.spec_helper) { rspec.spec_dir }
36
+ watch(rspec.spec_support) { rspec.spec_dir }
37
+ watch(rspec.spec_files)
38
+
39
+ # Ruby files
40
+ ruby = dsl.ruby
41
+ dsl.watch_spec_files_for(ruby.lib_files)
42
+
43
+ # Rails files
44
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
45
+ dsl.watch_spec_files_for(rails.app_files)
46
+ dsl.watch_spec_files_for(rails.views)
47
+
48
+ watch(rails.controllers) do |m|
49
+ [
50
+ rspec.spec.call("routing/#{m[1]}_routing"),
51
+ rspec.spec.call("controllers/#{m[1]}_controller"),
52
+ rspec.spec.call("acceptance/#{m[1]}")
53
+ ]
54
+ end
55
+
56
+ # Rails config changes
57
+ watch(rails.spec_helper) { rspec.spec_dir }
58
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
59
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
60
+
61
+ # Capybara features specs
62
+ watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
63
+ watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
64
+
65
+ # Turnip features and steps
66
+ watch(%r{^spec/acceptance/(.+)\.feature$})
67
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
68
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
69
+ end
70
+ end
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,74 @@
1
+ <!-- vim-markdown-toc GFM -->
2
+
3
+ + [case_transform2](#case_transform2)
4
+ * [Why](#why)
5
+ * [Install](#install)
6
+ * [Usage](#usage)
7
+ * [Transforms](#transforms)
8
+ * [NOTE](#note)
9
+
10
+ <!-- vim-markdown-toc -->
11
+
12
+ # case_transform2
13
+
14
+ [![Build Status](https://travis-ci.org/saiqulhaq/case_transform.svg?branch=master)](https://travis-ci.org/saiqulhaq/case_transform)
15
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/0050890b14e7f9165680/test_coverage)](https://codeclimate.com/github/saiqulhaq/case_transform/test_coverage)
16
+ [![Maintainability](https://api.codeclimate.com/v1/badges/0050890b14e7f9165680/maintainability)](https://codeclimate.com/github/saiqulhaq/case_transform/maintainability)
17
+
18
+
19
+ Transforms string letter case to camel, snake, dash and underscore without activesupport dependencies.
20
+ Forked from [Rails API CaseTransform gem](https://github.com/rails-api/case_transform)
21
+
22
+ ## Why
23
+
24
+ We want a simple string method without polluting String class and lightweight.
25
+ If you want to use this into Rails application or any Ruby application with activesupport dependencies,
26
+ you might want to consider [the original one instead.](https://github.com/rails-api/case_transform)
27
+
28
+ ## Install
29
+
30
+ ```ruby
31
+ gem 'case_transform2'
32
+ ```
33
+
34
+ or
35
+
36
+ ```bash
37
+ gem install case_transform2
38
+ ```
39
+
40
+ ## Usage
41
+
42
+ ```ruby
43
+ require 'case_transform2'
44
+
45
+ value = "hello_world"
46
+ CaseTransform.camel_lower(value) # => helloWorld
47
+
48
+ value = "hello_world"
49
+ CaseTransform.camel(value) # => HelloWorld
50
+
51
+ value = "hello_world"
52
+ CaseTransform.dash(value) # => hello-world
53
+
54
+ value = "helloWorld"
55
+ CaseTransform.underscore(value) # => hello_world
56
+ ```
57
+
58
+ `value` can be any of Array, Hash, Symbol, or String.
59
+ Any other object type will just be returned.
60
+
61
+ ## Transforms
62
+
63
+ | &nbsp; | Description |
64
+ | --- | --- |
65
+ | camel | PascalCase |
66
+ | camel_lower | camelCase |
67
+ | dash | dash-case |
68
+ | underscore | under_score |
69
+
70
+ ## NOTE
71
+
72
+ There is no `CaseTransform.unaltered` method like the original gem has
73
+
74
+ License MIT
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "case_transform/version"
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "case_transform2"
9
+ s.version = CaseTransform::VERSION
10
+ s.license = "MIT"
11
+ s.authors = ["L. Preston Sego III", "Ben Mills", "Saiqul Haq"]
12
+ s.email = "saiqulhaq@gmail.com"
13
+ s.homepage = "https://github.com/saiqulhaq/case_transform"
14
+ s.summary = "Transforms string letter case to camel, snake, dash and underscore without activesupport dependencies"
15
+ s.description = s.summary + ". Forked from https://github.com/rails-api/case_transform"
16
+ s.metadata["yard.run"] = "yri"
17
+ s.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+
21
+ s.bindir = "exe"
22
+ s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ s.require_path = ["lib"]
24
+
25
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
26
+
27
+ s.add_development_dependency "pry", "~> 0.10.4"
28
+ s.add_development_dependency "rake", "~> 11.2.2"
29
+ s.add_development_dependency "rspec", "~> 3.7.0"
30
+ s.add_development_dependency "simplecov", "~> 0.16.1"
31
+ end
@@ -0,0 +1,112 @@
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
@@ -0,0 +1,24 @@
1
+ module CaseTransform
2
+ class HashExt
3
+ def deep_transform_keys!(object, &block)
4
+ _deep_transform_keys_in_object!(object, &block)
5
+ end
6
+
7
+ private
8
+
9
+ def _deep_transform_keys_in_object!(object, &block)
10
+ case object
11
+ when Hash
12
+ object.keys.each do |key|
13
+ value = object.delete(key)
14
+ object[yield(key)] = _deep_transform_keys_in_object!(value, &block)
15
+ end
16
+ object
17
+ when Array
18
+ object.map! { |e| _deep_transform_keys_in_object!(e, &block) }
19
+ else
20
+ object
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CaseTransform
4
+ # String class extension
5
+ # Stolen from ActiveSupport::Inflector.camelize
6
+ class StringExt
7
+ def camelize(string, first_letter = :upper)
8
+ raise ArgumentError, "Argument can not be nil" unless %i[upper lower].include?(first_letter)
9
+ str = string.to_s
10
+ str = str.gsub(/^[a-z\d]*/, &:capitalize) if first_letter == :upper
11
+ str.gsub(/(?:_|(\/))([a-z\d]*)/i) do
12
+ "#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}"
13
+ end.gsub("/", "::")
14
+ end
15
+
16
+ def dasherize(string)
17
+ string.tr("_", "-")
18
+ end
19
+
20
+ # Only support camel to underscore
21
+ def underscore(string)
22
+ str = string.to_s
23
+ return str unless str =~ /[A-Z-]|::/
24
+ str.gsub("::", "/")
25
+ .gsub(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
26
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
27
+ .tr("-", "_")
28
+ .downcase
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+ module CaseTransform
3
+ VERSION = '0.2'.freeze
4
+ end
@@ -0,0 +1,2 @@
1
+ require "case_transform"
2
+ module CaseTransform2; end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: case_transform2
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.2'
5
+ platform: ruby
6
+ authors:
7
+ - L. Preston Sego III
8
+ - Ben Mills
9
+ - Saiqul Haq
10
+ autorequire:
11
+ bindir: exe
12
+ cert_chain: []
13
+ date: 2018-05-06 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: pry
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: 0.10.4
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: 0.10.4
29
+ - !ruby/object:Gem::Dependency
30
+ name: rake
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: 11.2.2
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: 11.2.2
43
+ - !ruby/object:Gem::Dependency
44
+ name: rspec
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: 3.7.0
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: 3.7.0
57
+ - !ruby/object:Gem::Dependency
58
+ name: simplecov
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: 0.16.1
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: 0.16.1
71
+ description: Transforms string letter case to camel, snake, dash and underscore without
72
+ activesupport dependencies. Forked from https://github.com/rails-api/case_transform
73
+ email: saiqulhaq@gmail.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".codeclimate.yml"
79
+ - ".gitignore"
80
+ - ".rspec"
81
+ - ".rubocop.yml"
82
+ - ".travis.yml"
83
+ - Gemfile
84
+ - Gemfile.lock
85
+ - Guardfile
86
+ - LICENSE
87
+ - README.md
88
+ - 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
94
+ - lib/case_transform2.rb
95
+ homepage: https://github.com/saiqulhaq/case_transform
96
+ licenses:
97
+ - MIT
98
+ metadata:
99
+ yard.run: yri
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.5.2
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Transforms string letter case to camel, snake, dash and underscore without
120
+ activesupport dependencies
121
+ test_files: []