case_transform 0.1 → 0.2

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
2
  SHA1:
3
- metadata.gz: d3c8657db46167f5dedf62a6352b2633ed4648c3
4
- data.tar.gz: 35bda195d78f3568e5b519ceb7c7e0c08f9dcd99
3
+ metadata.gz: 349b4cf3d1e50b96419859dd08603f4c946cbdde
4
+ data.tar.gz: d62a84b9a7b6b9ddd0be81fd52db62b464211e0a
5
5
  SHA512:
6
- metadata.gz: 9fd74f7f2a60855bea9697b2c01e7d51164287f88321b659e796fa3809eb61c6777a5ae95149a9f8b721a20fcd965712c92eea97336fe4b4697d6626774cc582
7
- data.tar.gz: 24b256717c863806d462c080af1795ae65a76038f0ec682755360798b229cec6f9d8c2561d6a832d2bbd109ee61e4d9550bb01a513cd909014d57bb7a399e489
6
+ metadata.gz: 9ccc13d4d8e83fc6126adf7002ed8cd8456b8d1d4b7ef04f4259021e87f79f6ff2ab65e802d4c6afe0dafcc6c0030f02a3a5bcec1cabf72ee4f2f9cf68e7e2f7
7
+ data.tar.gz: 54bac3ab172a6dd2a02322d98cdca8020dde5782b2c52108a29b509fc112e86532dae80c40d3bce1d6d1d9f8c0f66817db44e10a708739f57556254e78858d18
data/README.md CHANGED
@@ -1,23 +1,34 @@
1
- # key_transform
1
+ # case_transform
2
2
  Extraction of the key_transform abilities of ActiveModelSerializers
3
3
 
4
+ [![Gem Version](https://badge.fury.io/rb/case_transform.svg)](https://badge.fury.io/rb/case_transform)
5
+ [![Build Status](https://travis-ci.org/NullVoxPopuli/case_transform.svg?branch=master)](https://travis-ci.org/NullVoxPopuli/case_transform)
6
+ [![Code Climate](https://codeclimate.com/repos/57dafbcc628330006c001312/badges/5f190457aba7c5d5d78c/gpa.svg)](https://codeclimate.com/repos/57dafbcc628330006c001312/feed)
7
+ [![Test Coverage](https://codeclimate.com/repos/57dafbcc628330006c001312/badges/5f190457aba7c5d5d78c/coverage.svg)](https://codeclimate.com/repos/57dafbcc628330006c001312/coverage)
8
+ [![Dependency Status](https://gemnasium.com/NullVoxPopuli/case_transform.svg)](https://gemnasium.com/NullVoxPopuli/case_transform)
9
+
4
10
  ## Install
5
11
 
6
12
  ```ruby
7
- gem 'key_transform'
13
+ gem 'case_transform'
8
14
  ```
9
15
 
10
16
  or
11
17
 
12
- ```ruby
13
- require 'key_transform'
18
+ ```bash
19
+ gem install case_transform
14
20
  ```
15
21
  ## Usage
16
22
 
17
23
  ```ruby
24
+ require 'case_transform'
25
+
18
26
  CaseTransform.camel_lower(value)
19
27
  ```
20
28
 
29
+ `value` can be any of Array, Hash, Symbol, or String.
30
+ Any other object type will just be returned.
31
+
21
32
  ### Transforms
22
33
 
23
34
  |   | Description |
@@ -5,7 +5,22 @@ require 'active_support/core_ext/string'
5
5
  require 'case_transform/version'
6
6
 
7
7
  module CaseTransform
8
- module_function
8
+ class << self
9
+ def camel_cache
10
+ @camel_cache ||= {}
11
+ end
12
+
13
+ def camel_lower_cache
14
+ @camel_lower_cache ||= {}
15
+ end
16
+
17
+ def dash_cache
18
+ @dash_cache ||= {}
19
+ end
20
+
21
+ def underscore_cache
22
+ @underscore_cache ||= {}
23
+ end
9
24
 
10
25
  # Transforms values to UpperCamelCase or PascalCase.
11
26
  #
@@ -16,7 +31,7 @@ module CaseTransform
16
31
  when Array then value.map { |item| camel(item) }
17
32
  when Hash then value.deep_transform_keys! { |key| camel(key) }
18
33
  when Symbol then camel(value.to_s).to_sym
19
- when String then value.underscore.camelize
34
+ when String then camel_cache[value] ||= value.underscore.camelize
20
35
  else value
21
36
  end
22
37
  end
@@ -30,7 +45,7 @@ module CaseTransform
30
45
  when Array then value.map { |item| camel_lower(item) }
31
46
  when Hash then value.deep_transform_keys! { |key| camel_lower(key) }
32
47
  when Symbol then camel_lower(value.to_s).to_sym
33
- when String then value.underscore.camelize(:lower)
48
+ when String then camel_lower_cache[value] ||= value.underscore.camelize(:lower)
34
49
  else value
35
50
  end
36
51
  end
@@ -45,7 +60,7 @@ module CaseTransform
45
60
  when Array then value.map { |item| dash(item) }
46
61
  when Hash then value.deep_transform_keys! { |key| dash(key) }
47
62
  when Symbol then dash(value.to_s).to_sym
48
- when String then value.underscore.dasherize
63
+ when String then dash_cache[value] ||= value.underscore.dasherize
49
64
  else value
50
65
  end
51
66
  end
@@ -60,7 +75,7 @@ module CaseTransform
60
75
  when Array then value.map { |item| underscore(item) }
61
76
  when Hash then value.deep_transform_keys! { |key| underscore(key) }
62
77
  when Symbol then underscore(value.to_s).to_sym
63
- when String then value.underscore
78
+ when String then underscore_cache[value] ||= value.underscore
64
79
  else value
65
80
  end
66
81
  end
@@ -69,4 +84,5 @@ module CaseTransform
69
84
  def unaltered(value)
70
85
  value
71
86
  end
87
+ end
72
88
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module CaseTransform
3
- VERSION = '0.1'.freeze
3
+ VERSION = '0.2'.freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: case_transform
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - L. Preston Sego III
8
+ - Ben Mills
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2016-09-15 00:00:00.000000000 Z
12
+ date: 2016-09-22 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: activesupport
@@ -24,6 +25,20 @@ dependencies:
24
25
  - - ">="
25
26
  - !ruby/object:Gem::Version
26
27
  version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
27
42
  - !ruby/object:Gem::Dependency
28
43
  name: rubocop
29
44
  requirement: !ruby/object:Gem::Requirement
@@ -127,5 +142,5 @@ rubyforge_project:
127
142
  rubygems_version: 2.5.1
128
143
  signing_key:
129
144
  specification_version: 4
130
- summary: CaseTransform-0.1
145
+ summary: CaseTransform-0.2
131
146
  test_files: []