awrence 1.0.0 → 1.1.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: cbb0ff5ac0e9a4c22394ae4a2ca492701538fbf0
4
- data.tar.gz: bea61bb8c897f5ffd5a9c4946c932d6d5951bd28
2
+ SHA256:
3
+ metadata.gz: d5ed1bafd204d0f5d584f47dbb0ef8f4c211031eda888920078104141823dfbd
4
+ data.tar.gz: d29a22a0c9f9f5e18a6b78de602b50ef4ac24a86b20c3512accc56ec55b6ab9d
5
5
  SHA512:
6
- metadata.gz: fe6a8e89fc9ae1881fb3e06cff4107d8fd61b2484bf3a0724880f55795ca70e233fd4530775aab5490cb3a4f7432837d30ed623b4f954c44c267cb19a957bae1
7
- data.tar.gz: 7479507a51b038c95a37780aa66f7b542c1198809ccf92ea95bfa00af8d627b5ae530502389946c4a1eead794a0027f95b7c93a0192eb979a769a9c1de74c076
6
+ metadata.gz: 4ca478ed67cf46ca895af7f75e41ce4639e945bea155a330730586625df465cced767d995dcdcedd223021ddd049f031b94b1c412c6c9b4de7a3f1e69c792f2a
7
+ data.tar.gz: 566e6cbf587fee37134913359821856021d1254a07e258594d25cac63885fcb9d458850bd7701e430ec6a04df54ea96948305939556d1a49a965ed34aef0a945
data/README.md CHANGED
@@ -67,7 +67,7 @@ camel_hash = my_hash.to_camelback_keys
67
67
 
68
68
  ## Limitations
69
69
 
70
- * Unlike the original [T.E. Lawrence](http://en.wikipedia.org/wiki/T._E._Lawrence), the awrence gem is non-destructive to Hashes, Turks, or the nascent political aspirations of oppressed peoples. There is no `Hash#to_camel_keys!` form.
70
+ * There is no `Hash#to_camel_keys!` form.
71
71
 
72
72
  # Going the other way
73
73
 
@@ -84,7 +84,6 @@ the [Plissken](http://github.com/futurechimp/plissken) gem.
84
84
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
85
85
  * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
86
86
 
87
- == Copyright
87
+ # Copyright
88
88
 
89
- Copyright (c) 2017 Dave Hrycyszyn. See LICENSE.txt for
90
- further details.
89
+ Copyright (c) 2017 Dave Hrycyszyn. See LICENSE.txt for further details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "awrence/methods"
2
4
  require "awrence/ext/array/to_camel_keys"
3
5
  require "awrence/ext/hash/to_camel_keys"
4
6
 
5
7
  module Awrence
6
8
  class << self
7
-
8
9
  attr_writer :acronyms
9
10
 
10
11
  def acronyms
@@ -1,5 +1,5 @@
1
- class Array
1
+ # frozen_string_literal: true
2
2
 
3
+ class Array
3
4
  include Awrence::Methods
4
-
5
5
  end
@@ -1,5 +1,5 @@
1
- class Hash
1
+ # frozen_string_literal: true
2
2
 
3
+ class Hash
3
4
  include Awrence::Methods
4
-
5
5
  end
@@ -2,18 +2,17 @@
2
2
 
3
3
  module Awrence
4
4
  module Methods
5
-
6
5
  # Recursively converts Rubyish snake_case hash keys to camelBack JSON-style
7
6
  # hash keys suitable for use with a JSON API.
8
7
  #
9
8
  def to_camelback_keys(value = self)
10
9
  case value
11
- when Array
12
- value.map { |v| to_camelback_keys(v) }
13
- when Hash
14
- Hash[value.map { |k, v| [camelize_key(k, false), to_camelback_keys(v)] }]
15
- else
16
- value
10
+ when Array
11
+ value.map { |v| to_camelback_keys(v) }
12
+ when Hash
13
+ Hash[value.map { |k, v| [camelize_key(k, false), to_camelback_keys(v)] }]
14
+ else
15
+ value
17
16
  end
18
17
  end
19
18
 
@@ -22,32 +21,33 @@ module Awrence
22
21
  #
23
22
  def to_camel_keys(value = self)
24
23
  case value
25
- when Array
26
- value.map { |v| to_camel_keys(v) }
27
- when Hash
28
- Hash[value.map { |k, v| [camelize_key(k), to_camel_keys(v)] }]
29
- else
30
- value
24
+ when Array
25
+ value.map { |v| to_camel_keys(v) }
26
+ when Hash
27
+ Hash[value.map { |k, v| [camelize_key(k), to_camel_keys(v)] }]
28
+ else
29
+ value
31
30
  end
32
31
  end
33
32
 
34
33
  private
35
34
 
36
- def camelize_key(k, first_upper = true)
37
- if k.is_a? Symbol
38
- camelize(k.to_s, first_upper).to_sym
39
- elsif k.is_a? String
40
- camelize(k, first_upper)
35
+ def camelize_key(key, first_upper = true)
36
+ if key.is_a? Symbol
37
+ camelize(key.to_s, first_upper).to_sym
38
+ elsif key.is_a? String
39
+ camelize(key, first_upper)
41
40
  else
42
- k # Awrence can't camelize anything except strings and symbols
41
+ key # Awrence can't camelize anything except strings and symbols
43
42
  end
44
43
  end
45
44
 
46
45
  def camelize(snake_word, first_upper = true)
47
46
  if first_upper
48
- snake_word.to_s
49
- .gsub(/(?:^|_)([^_\s]+)/) { Awrence.acronyms[$1] || $1.capitalize }
50
- .gsub(%r|/([^/]*)|) { "::" + (Awrence.acronyms[$1] || $1.capitalize) }
47
+ str = snake_word.to_s
48
+ str = gsubbed(str, /(?:^|_)([^_\s]+)/)
49
+ str = gsubbed(str, %r{/([^/]*)}, "::")
50
+ str
51
51
  else
52
52
  parts = snake_word.split("_", 2)
53
53
  parts[0] << camelize(parts[1]) if parts.size > 1
@@ -55,5 +55,12 @@ module Awrence
55
55
  end
56
56
  end
57
57
 
58
+ def gsubbed(str, pattern, extra = "")
59
+ str = str.gsub(pattern) do
60
+ extra + (Awrence.acronyms[Regexp.last_match(1)] || Regexp.last_match(1).capitalize)
61
+ end
62
+
63
+ str
64
+ end
58
65
  end
59
66
  end
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Awrence
2
- VERSION = File.read("VERSION").split("\n").first
4
+ version_file = File.join(File.dirname(__FILE__), "../../VERSION")
5
+ VERSION = File.read(version_file).split("\n").first
3
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awrence
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Hrycyszyn
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-07-19 00:00:00.000000000 Z
12
+ date: 2019-01-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
@@ -17,28 +17,42 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '4.7'
20
+ version: '5.0'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '4.7'
27
+ version: '5.0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: minitest-fail-fast
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '0.1'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '0.1'
28
42
  - !ruby/object:Gem::Dependency
29
43
  name: minitest-reporters
30
44
  requirement: !ruby/object:Gem::Requirement
31
45
  requirements:
32
46
  - - "~>"
33
47
  - !ruby/object:Gem::Version
34
- version: '0.14'
48
+ version: '1.3'
35
49
  type: :development
36
50
  prerelease: false
37
51
  version_requirements: !ruby/object:Gem::Requirement
38
52
  requirements:
39
53
  - - "~>"
40
54
  - !ruby/object:Gem::Version
41
- version: '0.14'
55
+ version: '1.3'
42
56
  - !ruby/object:Gem::Dependency
43
57
  name: rake
44
58
  requirement: !ruby/object:Gem::Requirement
@@ -92,8 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
106
  - !ruby/object:Gem::Version
93
107
  version: '0'
94
108
  requirements: []
95
- rubyforge_project:
96
- rubygems_version: 2.6.11
109
+ rubygems_version: 3.0.1
97
110
  signing_key:
98
111
  specification_version: 4
99
112
  summary: Camelize your snake keys when working with JSON APIs