awrence 1.1.1 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +15 -12
  4. data/VERSION +1 -1
  5. data/lib/awrence/methods.rb +21 -26
  6. metadata +13 -110
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e6e73efbae530af96c6c5c1caf823db5d81ec070b77d89aa7d093637e06b044e
4
- data.tar.gz: 849878bc1194cd17fa87ebd167cf6c528f9e652c0cdb1601abcf06312e234379
3
+ metadata.gz: b9ad31efa3716cc6e0c4c10654a506a549e6e707adf5f7849cc237878c726dd7
4
+ data.tar.gz: e37015d0e7a72a7588c8acc405bf89f1906cbc6372da64d27d991f312722e1c2
5
5
  SHA512:
6
- metadata.gz: c065c41db56ffa81fcde1d6d703490d2d4129dc47877d613e8a2514fdc5bf48a6e76514985586d66da0259391c5caa65758ea1f66796038764f324b137b43f8f
7
- data.tar.gz: 534ba6b002fca71ea307b935435f9ee7d922dc873243a83859f3f72462973455b4247085f81944c0bfb87352f8f423cc98259f1b584d9f2bff6d47d74bf37ad6
6
+ metadata.gz: 7bc7dbc91cdc47d7fcc49fea9a91033916628f9f93993742e83ff06eb71afa290bd8a029525cf1e87e8c21b4667e5a38166ba89894e264de3fadd24664b95184
7
+ data.tar.gz: f103746aef4c264b6e38e034a9e20e6f88660c10c26a3a03661f221431fbca3c8082838f0b21c4befa44f58c3dc04ffffcd3d9e56f616fafa4e7616678712ae1
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2020 Dave Hrycyszyn
1
+ Copyright (c) 2021 Technical Panda Ltd
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,13 +1,18 @@
1
1
  # Awrence
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/awrence.svg)](https://badge.fury.io/rb/awrence)
4
+ ![CI](https://github.com/technicalpanda/awrence/workflows/CI/badge.svg)
4
5
 
5
- Have you ever needed to automatically convert Rubyish `snake_case` to JSON-style `camelBack` or `CamelCase` hash keys?
6
+ Have you ever needed to automatically convert Rubyish `snake_case` to JSON-style `camelBack` or `CamelCase` hash keys?
6
7
 
7
- Awrence to the rescue.
8
+ Awrence to the rescue!
8
9
 
9
10
  This gem recursively converts all snake_case keys in a hash structure to camelBack or CamelCase.
10
11
 
12
+ ## Requirements
13
+
14
+ * Ruby >= 2.7
15
+
11
16
  ## Installation
12
17
 
13
18
  Add this to your Gemfile:
@@ -74,16 +79,14 @@ camel_hash = my_hash.to_camelback_keys
74
79
  If you've already got `CamelCase` and need to `snake_case` it, you are encouraged to try
75
80
  the [Plissken](http://github.com/futurechimp/plissken) gem.
76
81
 
77
- ## Contributing to awrence
82
+ ## Contributing
83
+
84
+ Bug reports and pull requests are welcome on GitHub at https://github.com/technicalpanda/awrence. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
85
+
86
+ ## License
78
87
 
79
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
80
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
81
- * Fork the project.
82
- * Start a feature/bugfix branch.
83
- * Commit and push until you are happy with your contribution.
84
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
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.
88
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
86
89
 
87
- # Copyright
90
+ ## Code of Conduct
88
91
 
89
- Copyright (c) 2017 Dave Hrycyszyn. See LICENSE.txt for further details.
92
+ Everyone interacting with this project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/technicalpanda/awrence/blob/main/CODE_OF_CONDUCT.md).
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.1
1
+ 2.0.1
@@ -6,48 +6,34 @@ module Awrence
6
6
  # hash keys suitable for use with a JSON API.
7
7
  #
8
8
  def to_camelback_keys(value = self)
9
- case 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
16
- end
9
+ process_value(:to_camelback_keys, value, first_upper: false)
17
10
  end
18
11
 
19
12
  # Recursively converts Rubyish snake_case hash keys to CamelCase JSON-style
20
13
  # hash keys suitable for use with a JSON API.
21
14
  #
22
15
  def to_camel_keys(value = self)
23
- case 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
30
- end
16
+ process_value(:to_camel_keys, value, first_upper: true)
31
17
  end
32
18
 
33
19
  private
34
20
 
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)
21
+ def camelize_key(key, first_upper: true)
22
+ case key
23
+ when Symbol
24
+ camelize(key.to_s, first_upper: first_upper).to_sym
25
+ when String
26
+ camelize(key, first_upper: first_upper)
40
27
  else
41
28
  key # Awrence can't camelize anything except strings and symbols
42
29
  end
43
30
  end
44
31
 
45
- def camelize(snake_word, first_upper = true)
32
+ def camelize(snake_word, first_upper: true)
46
33
  if first_upper
47
34
  str = snake_word.to_s
48
35
  str = gsubbed(str, /(?:^|_)([^_\s]+)/)
49
- str = gsubbed(str, %r{/([^/]*)}, "::")
50
- str
36
+ gsubbed(str, %r{/([^/]*)}, "::")
51
37
  else
52
38
  parts = snake_word.split("_", 2)
53
39
  parts[0] << camelize(parts[1]) if parts.size > 1
@@ -56,11 +42,20 @@ module Awrence
56
42
  end
57
43
 
58
44
  def gsubbed(str, pattern, extra = "")
59
- str = str.gsub(pattern) do
45
+ str.gsub(pattern) do
60
46
  extra + (Awrence.acronyms[Regexp.last_match(1)] || Regexp.last_match(1).capitalize)
61
47
  end
48
+ end
62
49
 
63
- str
50
+ def process_value(method, value, first_upper: true)
51
+ case value
52
+ when Array
53
+ value.map { |v| send(method, v) }
54
+ when Hash
55
+ value.to_h { |k, v| [camelize_key(k, first_upper: first_upper), send(method, v)] }
56
+ else
57
+ value
58
+ end
64
59
  end
65
60
  end
66
61
  end
metadata CHANGED
@@ -1,114 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awrence
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Hrycyszyn
8
8
  - Stuart Chinery
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-02-01 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: byebug
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - "~>"
19
- - !ruby/object:Gem::Version
20
- version: '11.1'
21
- type: :development
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - "~>"
26
- - !ruby/object:Gem::Version
27
- version: '11.1'
28
- - !ruby/object:Gem::Dependency
29
- name: minitest
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - "~>"
33
- - !ruby/object:Gem::Version
34
- version: '5.14'
35
- type: :development
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - "~>"
40
- - !ruby/object:Gem::Version
41
- version: '5.14'
42
- - !ruby/object:Gem::Dependency
43
- name: minitest-fail-fast
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - "~>"
47
- - !ruby/object:Gem::Version
48
- version: '0.1'
49
- type: :development
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - "~>"
54
- - !ruby/object:Gem::Version
55
- version: '0.1'
56
- - !ruby/object:Gem::Dependency
57
- name: minitest-macos-notification
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - "~>"
61
- - !ruby/object:Gem::Version
62
- version: '0.3'
63
- type: :development
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: '0.3'
70
- - !ruby/object:Gem::Dependency
71
- name: minitest-reporters
72
- requirement: !ruby/object:Gem::Requirement
73
- requirements:
74
- - - "~>"
75
- - !ruby/object:Gem::Version
76
- version: '1.4'
77
- type: :development
78
- prerelease: false
79
- version_requirements: !ruby/object:Gem::Requirement
80
- requirements:
81
- - - "~>"
82
- - !ruby/object:Gem::Version
83
- version: '1.4'
84
- - !ruby/object:Gem::Dependency
85
- name: rake
86
- requirement: !ruby/object:Gem::Requirement
87
- requirements:
88
- - - "~>"
89
- - !ruby/object:Gem::Version
90
- version: '13.0'
91
- type: :development
92
- prerelease: false
93
- version_requirements: !ruby/object:Gem::Requirement
94
- requirements:
95
- - - "~>"
96
- - !ruby/object:Gem::Version
97
- version: '13.0'
98
- - !ruby/object:Gem::Dependency
99
- name: rubocop
100
- requirement: !ruby/object:Gem::Requirement
101
- requirements:
102
- - - "~>"
103
- - !ruby/object:Gem::Version
104
- version: '0.79'
105
- type: :development
106
- prerelease: false
107
- version_requirements: !ruby/object:Gem::Requirement
108
- requirements:
109
- - - "~>"
110
- - !ruby/object:Gem::Version
111
- version: '0.79'
12
+ date: 2022-01-23 00:00:00.000000000 Z
13
+ dependencies: []
112
14
  description: |-
113
15
  Have you ever needed to automatically convert Ruby-style snake_case to CamelCase or camelBack hash keys?
114
16
 
@@ -116,8 +18,8 @@ description: |-
116
18
 
117
19
  This gem recursively converts all snake_case keys in a hash structure to camelBack.
118
20
  email:
119
- - dhrycyszyn@zonedigital.com
120
- - stuart.chinery@gmail.com
21
+ - dave@constructiveproof.com
22
+ - code@technicalpanda.co.uk
121
23
  executables: []
122
24
  extensions: []
123
25
  extra_rdoc_files: []
@@ -131,11 +33,12 @@ files:
131
33
  - lib/awrence/ext/hash/to_camel_keys.rb
132
34
  - lib/awrence/methods.rb
133
35
  - lib/awrence/version.rb
134
- homepage: https://github.com/futurechimp/awrence
36
+ homepage: https://github.com/technicalpanda/awrence
135
37
  licenses:
136
38
  - MIT
137
- metadata: {}
138
- post_install_message:
39
+ metadata:
40
+ rubygems_mfa_required: 'true'
41
+ post_install_message:
139
42
  rdoc_options: []
140
43
  require_paths:
141
44
  - lib
@@ -143,15 +46,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
46
  requirements:
144
47
  - - ">="
145
48
  - !ruby/object:Gem::Version
146
- version: '0'
49
+ version: '2.7'
147
50
  required_rubygems_version: !ruby/object:Gem::Requirement
148
51
  requirements:
149
52
  - - ">="
150
53
  - !ruby/object:Gem::Version
151
54
  version: '0'
152
55
  requirements: []
153
- rubygems_version: 3.1.2
154
- signing_key:
56
+ rubygems_version: 3.2.33
57
+ signing_key:
155
58
  specification_version: 4
156
59
  summary: Camelize your snake keys when working with JSON APIs
157
60
  test_files: []