cymbal 0.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
2
  SHA1:
3
- metadata.gz: 2d116c89ec40a5bfc69fbe8f9fc3d75bb7ebbc7c
4
- data.tar.gz: fd40e6eda668689815bfd4ac4068680ddd59261e
3
+ metadata.gz: 46af8544a2e5313854767692da1df0cf02265fe0
4
+ data.tar.gz: 13eada37ae64a98ac2c69df9efc1f3344ef34980
5
5
  SHA512:
6
- metadata.gz: 2fcf380ae74c66d56cce80f6ab4611a76b57936b01b863af9ea6ec1a8c4735921a963e44534f21af354e631584e71b12c5f4576a1009b42b61e32a353f36981a
7
- data.tar.gz: 8fce060295d6f50f333e68f01a6a975745256e16f8ae7ac7b64b0b0074035acac15ede1bfcedc8fdb15ac1c13db10b1b3c76b1b5296846605eb113aa276da426
6
+ metadata.gz: 149c0583d11ce168b5f7e24a7f55dc946ae9b554b389f9773b07ccbd9f97be87235f914641d42d28c407ced90b14a22a7668dbfd60d301d404d6869343a7d273
7
+ data.tar.gz: 9068d1616785b54f53f961c542459f2675b05cc27e00255cc0ff069127af0dc4057838e2f828db0b0b7aea7f7c2ff12aee50649892fad305f19b2dc1c76bbec7
@@ -1,11 +1,15 @@
1
1
  language: ruby
2
+ sudo: false
2
3
  cache: bundler
3
4
  rvm:
4
- - 2.1.0
5
- - 2.0.0
6
- - 1.9.3
5
+ - 2.2.0
6
+ - 2.1.5
7
+ - 2.0.0-p598
8
+ - 1.9.3-p551
7
9
  notifications:
8
10
  email: false
9
11
  irc:
10
12
  template:
11
- - '%{repository}/%{branch}/%{build_number}: %{message} -- %{build_url}'
13
+ - '%{repository}/%{branch}/%{build_number}: %{message} -- %{build_url}'
14
+ channels:
15
+ - irc.oftc.net#akerl
@@ -0,0 +1,4 @@
1
+ # 1.0.0 / 2015-01-22
2
+
3
+ * [ENHANCEMENT] Stabilized API
4
+
data/README.md CHANGED
@@ -24,6 +24,10 @@ x = {
24
24
  Cymbal.symbolize(x) # returns {:foo=>1, :bar=>{:cats=>6, :dogs=>"better"}}
25
25
  ```
26
26
 
27
+ The symbolize call will convert keys recursively and will handle an array of hashes.
28
+
29
+ If a hash includes keys that would collide (for example, :foo and 'foo'), an ArgumentError will be raised.
30
+
27
31
  ## Installation
28
32
 
29
33
  gem install cymbal
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'cymbal'
3
- s.version = '0.0.2'
3
+ s.version = '1.0.0'
4
4
  s.date = Time.now.strftime("%Y-%m-%d")
5
5
 
6
6
  s.summary = 'Converts hash keys from strings to symbols'
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  s.files = `git ls-files`.split
14
14
  s.test_files = `git ls-files spec/*`.split
15
15
 
16
- s.add_development_dependency 'rubocop', '~> 0.26.0'
17
- s.add_development_dependency 'rake', '~> 10.3.2'
16
+ s.add_development_dependency 'rubocop', '~> 0.28.0'
17
+ s.add_development_dependency 'rake', '~> 10.4.0'
18
18
  s.add_development_dependency 'coveralls', '~> 0.7.1'
19
19
  s.add_development_dependency 'rspec', '~> 3.1.0'
20
20
  s.add_development_dependency 'fuubar', '~> 2.0.0'
@@ -11,11 +11,20 @@ module Cymbal
11
11
  private
12
12
 
13
13
  def symbolize_hash(hash)
14
+ check_collisions(hash.keys)
14
15
  hash.each_with_object({}) { |(k, v), o| o[k.to_sym] = symbolize(v) }
15
16
  end
16
17
 
17
18
  def symbolize_array(array)
18
19
  array.map { |item| symbolize(item) }
19
20
  end
21
+
22
+ def check_collisions(keys)
23
+ symbols, other = keys.partition { |x| x.is_a? Symbol }
24
+ other.map!(&:to_sym)
25
+ overlap = other & symbols
26
+ return if overlap.empty?
27
+ fail ArgumentError, "Key collision in hash: #{overlap}"
28
+ end
20
29
  end
21
30
  end
@@ -1 +1,34 @@
1
1
  require 'spec_helper'
2
+
3
+ describe Cymbal do
4
+ describe '#symbolize' do
5
+ let(:hash) do
6
+ { 'foo' => 1, 'bar' => 2 }
7
+ end
8
+ let(:result) do
9
+ { foo: 1, bar: 2 }
10
+ end
11
+
12
+ it 'symbolizes hashes' do
13
+ expect(Cymbal.symbolize(hash)).to eql result
14
+ end
15
+
16
+ it 'symbolizes hashes in arrays' do
17
+ array = Cymbal.symbolize((1..5).collect { hash.dup })
18
+ correct = (1..5).collect { Cymbal.symbolize(hash.dup) }
19
+ expect(array).to eql correct
20
+ expect(array.first.keys).to include(:foo, :bar)
21
+ end
22
+
23
+ it 'raises if there is a key conflict' do
24
+ bad_hash = { 'foo' => 2, :foo => 3 }
25
+ expect { Cymbal.symbolize(bad_hash) }.to raise_error(ArgumentError)
26
+ end
27
+
28
+ it 'supports nested hashes' do
29
+ nested = Cymbal.symbolize('nest' => hash)
30
+ correct = { nest: Cymbal.symbolize(hash) }
31
+ expect(nested).to eql correct
32
+ end
33
+ end
34
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cymbal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Les Aker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-13 00:00:00.000000000 Z
11
+ date: 2015-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.26.0
19
+ version: 0.28.0
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.26.0
26
+ version: 0.28.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 10.3.2
33
+ version: 10.4.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 10.3.2
40
+ version: 10.4.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: coveralls
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -90,6 +90,7 @@ files:
90
90
  - ".rspec"
91
91
  - ".rubocop.yml"
92
92
  - ".travis.yml"
93
+ - CHANGELOG.md
93
94
  - Gemfile
94
95
  - LICENSE
95
96
  - README.md