hashslice 1.1.2 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/CHANGES.rdoc +5 -0
- data/Gemfile +6 -0
- data/MANIFEST.rdoc +2 -1
- data/Rakefile +4 -6
- data/hashslice.gemspec +23 -14
- data/lib/hashslice.rb +1 -1
- data/spec/hashslice_spec.rb +80 -0
- metadata +19 -12
- metadata.gz.sig +0 -0
- data/test/test_hashslice.rb +0 -94
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 846d78f8f3d0c07324618f622a2020ff9ea79401d05698ca6744938ae31ed301
|
4
|
+
data.tar.gz: da64ebcd8bed12fc2c1258c8c4443e5c759fb85d10e1ea12231b178a91dd5561
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca1dfa947f376f65c7a2f229b91a8681ed10d8f54328e4225ad37d4426898636631a9e2ea14fb28a7a869e67d9d2bb159cca64f0a9003db8ed2e1285c27f16e0
|
7
|
+
data.tar.gz: b88d35c86df40c4507c25b893a96dc6a7beceb5c2546e732c31c4ab3e16fc47f79dba7231df2d1f2c337d86b4b5feb689c65054b925514d49959d15ef629e7ce
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/CHANGES.rdoc
CHANGED
data/Gemfile
ADDED
data/MANIFEST.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'rake'
|
2
2
|
require 'rake/clean'
|
3
|
-
require '
|
3
|
+
require 'rspec/core/rake_task'
|
4
4
|
|
5
5
|
CLEAN.include("**/*.gem", "**/*.rbc")
|
6
6
|
|
@@ -20,9 +20,7 @@ namespace :gem do
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
t.verbose = true
|
26
|
-
end
|
23
|
+
desc "Run the test suite"
|
24
|
+
RSpec::Core::RakeTask.new(:spec)
|
27
25
|
|
28
|
-
task :default => :
|
26
|
+
task :default => :spec
|
data/hashslice.gemspec
CHANGED
@@ -1,22 +1,31 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
|
3
|
-
Gem::Specification.new do |
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'hashslice'
|
5
|
+
spec.version = '1.2.0'
|
6
|
+
spec.authors = ['Daniel J. Berger', 'Michael Granger']
|
7
|
+
spec.license = 'Artistic-2.0'
|
8
|
+
spec.email = 'djberg96@gmail.com'
|
9
|
+
spec.homepage = 'http://github.com/djberg96/hashslice'
|
10
|
+
spec.summary = "Adds hash slicing to Ruby's Hash class"
|
11
|
+
spec.test_file = 'spec/hashslice_spec.rb'
|
12
|
+
spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
|
13
|
+
spec.cert_chain = Dir['certs/*']
|
14
14
|
|
15
|
-
|
15
|
+
spec.extra_rdoc_files = ['README.rdoc', 'CHANGES.rdoc', 'MANIFEST.rdoc']
|
16
16
|
|
17
|
-
|
17
|
+
spec.add_development_dependency('rspec', '~> 3.9')
|
18
18
|
|
19
|
-
|
19
|
+
spec.metadata = {
|
20
|
+
'homepage_uri' => 'https://github.com/djberg96/hashslice',
|
21
|
+
'bug_tracker_uri' => 'https://github.com/djberg96/hashslice/issues',
|
22
|
+
'changelog_uri' => 'https://github.com/djberg96/hashslice/blob/master/CHANGES',
|
23
|
+
'documentation_uri' => 'https://github.com/djberg96/hashslice/wiki',
|
24
|
+
'source_code_uri' => 'https://github.com/djberg96/hashslice',
|
25
|
+
'wiki_uri' => 'https://github.com/djberg96/hashslice/wiki'
|
26
|
+
}
|
27
|
+
|
28
|
+
spec.description = <<-EOF
|
20
29
|
The hashslice library adds builtin hash slicing to Ruby's Hash class.
|
21
30
|
This lets you reference, or assign to, multiple hash keys simultaneously
|
22
31
|
via the Hash#[] and Hash#[]= methods, respectively.
|
data/lib/hashslice.rb
CHANGED
@@ -3,7 +3,7 @@ class Hash
|
|
3
3
|
alias hset []=
|
4
4
|
|
5
5
|
# The version of the hashslice library
|
6
|
-
VERSION_HASHSLICE = '1.
|
6
|
+
VERSION_HASHSLICE = '1.2.0'.freeze
|
7
7
|
|
8
8
|
# Retrieve a hash slice. If a single key is provided, returns a single
|
9
9
|
# value. If multiple keys are provided, an array of values is returned.
|
@@ -0,0 +1,80 @@
|
|
1
|
+
#######################################################################
|
2
|
+
# hashslice_spec.rb
|
3
|
+
#
|
4
|
+
# Test suite for the hashslice library. You should run these tests
|
5
|
+
# via the 'rake spec' task.
|
6
|
+
#######################################################################
|
7
|
+
require 'hashslice'
|
8
|
+
require 'rspec'
|
9
|
+
|
10
|
+
RSpec.describe Hash do
|
11
|
+
before do
|
12
|
+
@hash = {'a' => 1, 'b' => 2}
|
13
|
+
end
|
14
|
+
|
15
|
+
example "version" do
|
16
|
+
expect(Hash::VERSION_HASHSLICE).to eq('1.2.0')
|
17
|
+
expect(Hash::VERSION_HASHSLICE).to be_frozen
|
18
|
+
end
|
19
|
+
|
20
|
+
example "Hash#[] basic functionality" do
|
21
|
+
expect(@hash).to respond_to(:[])
|
22
|
+
expect{ @hash[] }.not_to raise_error
|
23
|
+
end
|
24
|
+
|
25
|
+
example "Hash#[] returns the expected value for a single argument" do
|
26
|
+
expect(@hash['a']).to eq(1)
|
27
|
+
expect(@hash['b']).to eq(2)
|
28
|
+
expect(@hash['c']).to eq(nil)
|
29
|
+
end
|
30
|
+
|
31
|
+
example "Hash#[] returns the expected value for multiple arguments" do
|
32
|
+
expect(@hash['a', 'b']).to eq([1, 2])
|
33
|
+
expect(@hash['b', 'a']).to eq([2, 1])
|
34
|
+
expect(@hash['a', 'b', 'c']).to eq([1, 2, nil])
|
35
|
+
end
|
36
|
+
|
37
|
+
example "Hash#[] returns the expected value for duplicate arguments" do
|
38
|
+
expect(@hash['a', 'a']).to eq([1, 1])
|
39
|
+
expect(@hash['a', 'b', 'a', 'b']).to eq([1, 2, 1, 2])
|
40
|
+
expect(@hash['a', 'a', 'c', 'c']).to eq([1, 1, nil, nil])
|
41
|
+
end
|
42
|
+
|
43
|
+
example "Hash#[]= basic functionality" do
|
44
|
+
expect(@hash).to respond_to(:[]=)
|
45
|
+
expect{ @hash['a'] = 3 }.not_to raise_error
|
46
|
+
expect{ @hash['a', 'b'] = 3 }.not_to raise_error
|
47
|
+
expect{ @hash['a', 'b'] = [3, 4] }.not_to raise_error
|
48
|
+
end
|
49
|
+
|
50
|
+
example "Hash#[]= with a single key and single value works as expected" do
|
51
|
+
expect(@hash['a'] = 3).to eq(3)
|
52
|
+
expect(@hash['a']).to eq(3)
|
53
|
+
expect(@hash['b'] = [4, 5]).to eq([4, 5])
|
54
|
+
expect(@hash['b']).to eq([4, 5])
|
55
|
+
end
|
56
|
+
|
57
|
+
example "Hash#[]= with a multiple keys and single value works as expected" do
|
58
|
+
expect(@hash['a', 'b'] = 3).to eq(3)
|
59
|
+
expect(@hash['a', 'b']).to eq([3, nil])
|
60
|
+
end
|
61
|
+
|
62
|
+
example "Hash#[]= with a multiple keys and multiple values works as expected" do
|
63
|
+
expect(@hash['a', 'b'] = [3, 4]).to eq([3, 4])
|
64
|
+
expect(@hash['a', 'b']).to eq([3, 4])
|
65
|
+
end
|
66
|
+
|
67
|
+
example "Hash#[]= with a multiple keys and an odd number of values works as expected" do
|
68
|
+
expect{ @hash['a', 'b'] = 3, 4, 5 }.not_to raise_error
|
69
|
+
expect(@hash).to eq({'a' => 3, 'b' => 4})
|
70
|
+
end
|
71
|
+
|
72
|
+
example "slice_alias" do
|
73
|
+
expect(Hash.instance_method(:slice)).to eql(Hash.instance_method(:[]))
|
74
|
+
end
|
75
|
+
|
76
|
+
example "hash_of returns a sub hash" do
|
77
|
+
expect(@hash).to respond_to(:hash_of)
|
78
|
+
expect(@hash.hash_of('a', 'b')).to eq({'a' => 1, 'b' => 2})
|
79
|
+
end
|
80
|
+
end
|
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hashslice
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel J. Berger
|
8
8
|
- Michael Granger
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain:
|
12
12
|
- |
|
@@ -36,22 +36,22 @@ cert_chain:
|
|
36
36
|
ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
|
37
37
|
WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
|
38
38
|
-----END CERTIFICATE-----
|
39
|
-
date: 2020-
|
39
|
+
date: 2020-09-23 00:00:00.000000000 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '3'
|
47
|
+
version: '3.9'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '3'
|
54
|
+
version: '3.9'
|
55
55
|
description: |2
|
56
56
|
The hashslice library adds builtin hash slicing to Ruby's Hash class.
|
57
57
|
This lets you reference, or assign to, multiple hash keys simultaneously
|
@@ -65,18 +65,25 @@ extra_rdoc_files:
|
|
65
65
|
- MANIFEST.rdoc
|
66
66
|
files:
|
67
67
|
- CHANGES.rdoc
|
68
|
+
- Gemfile
|
68
69
|
- MANIFEST.rdoc
|
69
70
|
- README.rdoc
|
70
71
|
- Rakefile
|
71
72
|
- certs/djberg96_pub.pem
|
72
73
|
- hashslice.gemspec
|
73
74
|
- lib/hashslice.rb
|
74
|
-
-
|
75
|
+
- spec/hashslice_spec.rb
|
75
76
|
homepage: http://github.com/djberg96/hashslice
|
76
77
|
licenses:
|
77
78
|
- Artistic-2.0
|
78
|
-
metadata:
|
79
|
-
|
79
|
+
metadata:
|
80
|
+
homepage_uri: https://github.com/djberg96/hashslice
|
81
|
+
bug_tracker_uri: https://github.com/djberg96/hashslice/issues
|
82
|
+
changelog_uri: https://github.com/djberg96/hashslice/blob/master/CHANGES
|
83
|
+
documentation_uri: https://github.com/djberg96/hashslice/wiki
|
84
|
+
source_code_uri: https://github.com/djberg96/hashslice
|
85
|
+
wiki_uri: https://github.com/djberg96/hashslice/wiki
|
86
|
+
post_install_message:
|
80
87
|
rdoc_options: []
|
81
88
|
require_paths:
|
82
89
|
- lib
|
@@ -91,9 +98,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
98
|
- !ruby/object:Gem::Version
|
92
99
|
version: '0'
|
93
100
|
requirements: []
|
94
|
-
rubygems_version: 3.
|
95
|
-
signing_key:
|
101
|
+
rubygems_version: 3.1.4
|
102
|
+
signing_key:
|
96
103
|
specification_version: 4
|
97
104
|
summary: Adds hash slicing to Ruby's Hash class
|
98
105
|
test_files:
|
99
|
-
-
|
106
|
+
- spec/hashslice_spec.rb
|
metadata.gz.sig
CHANGED
Binary file
|
data/test/test_hashslice.rb
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
#######################################################################
|
2
|
-
# test_hashslice.rb
|
3
|
-
#
|
4
|
-
# Test suite for the hashslice library. You should run these tests
|
5
|
-
# via the 'rake test' task.
|
6
|
-
#######################################################################
|
7
|
-
require 'rubygems'
|
8
|
-
require 'hashslice'
|
9
|
-
require 'test-unit'
|
10
|
-
|
11
|
-
class TC_Hashslice < Test::Unit::TestCase
|
12
|
-
def setup
|
13
|
-
@hash = {'a' => 1, 'b' => 2}
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_version
|
17
|
-
assert_equal('1.1.2', Hash::VERSION_HASHSLICE)
|
18
|
-
assert_true(Hash::VERSION_HASHSLICE.frozen?)
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_get_slice_instance_method_basic
|
22
|
-
assert_respond_to(@hash, :[])
|
23
|
-
assert_nothing_raised{ @hash['a'] }
|
24
|
-
assert_nothing_raised{ @hash['a', 'b'] }
|
25
|
-
assert_kind_of(Integer, @hash['a'])
|
26
|
-
assert_kind_of(Array, @hash['a', 'b'])
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_get_slice_instance_method
|
30
|
-
assert_equal(1, @hash['a'])
|
31
|
-
assert_equal([1, 2], @hash['a', 'b'])
|
32
|
-
assert_equal([1, 2, nil], @hash['a', 'b', 'c'])
|
33
|
-
assert_nil(@hash['bogus'])
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_get_slice_duplicate_keys
|
37
|
-
assert_equal([1, 1], @hash['a', 'a'])
|
38
|
-
assert_equal([1, 2, 1, 2], @hash['a', 'b', 'a', 'b'])
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_set_slice_instance_method_basic
|
42
|
-
assert_respond_to(@hash, :[]=)
|
43
|
-
assert_nothing_raised{ @hash['a'] = 3 }
|
44
|
-
assert_nothing_raised{ @hash['a', 'b'] = 3 }
|
45
|
-
assert_nothing_raised{ @hash['a', 'b'] = 3, 4 }
|
46
|
-
assert_kind_of(Integer, @hash['a'] = 3)
|
47
|
-
assert_kind_of(Integer, @hash['a', 'b'] = 3)
|
48
|
-
assert_kind_of(Integer, @hash['a', 'b'] = 3, 4)
|
49
|
-
end
|
50
|
-
|
51
|
-
# hash[key] = value
|
52
|
-
def test_set_slice_instance_method_single_key_and_value
|
53
|
-
assert_nothing_raised{ @hash['a'] = 3 }
|
54
|
-
assert_nothing_raised{ @hash['b'] = [1, 2] }
|
55
|
-
assert_equal({'a' => 3, 'b' => [1, 2]}, @hash)
|
56
|
-
end
|
57
|
-
|
58
|
-
# hash[key1, key2] = value
|
59
|
-
def test_set_slice_instance_method_multiple_keys_single_value
|
60
|
-
assert_nothing_raised{ @hash['a', 'b'] = 3 }
|
61
|
-
assert_equal({'a' => 3, 'b' => nil}, @hash)
|
62
|
-
end
|
63
|
-
|
64
|
-
# hash[key1, key2] = value1, value2
|
65
|
-
def test_set_slice_instance_method_multiple_keys_multiple_values
|
66
|
-
assert_nothing_raised{ @hash['a', 'b'] = 3, 4 }
|
67
|
-
assert_equal({'a' => 3, 'b' => 4}, @hash)
|
68
|
-
end
|
69
|
-
|
70
|
-
# hash[key] = value1, value2
|
71
|
-
def test_set_slice_instance_method_single_key_multiple_values
|
72
|
-
assert_nothing_raised{ @hash['a'] = 3, 4 }
|
73
|
-
assert_equal({'a' => [3, 4], 'b' => 2}, @hash)
|
74
|
-
end
|
75
|
-
|
76
|
-
# hash[key1, key2] = value1, value2, value3
|
77
|
-
def test_set_slice_instance_method_multiple_keys_odd_values
|
78
|
-
assert_nothing_raised{ @hash['a', 'b'] = 3, 4, 5 }
|
79
|
-
assert_equal({'a' => 3, 'b' => 4}, @hash)
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_slice_alias
|
83
|
-
assert_true(Hash.instance_method(:slice) == Hash.instance_method(:[]))
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_hash_of
|
87
|
-
assert_respond_to(@hash, :hash_of)
|
88
|
-
assert_equal({'a' => 1, 'b' => 2}, @hash.hash_of('a', 'b'))
|
89
|
-
end
|
90
|
-
|
91
|
-
def teardown
|
92
|
-
@hash = nil
|
93
|
-
end
|
94
|
-
end
|