triad 0.3.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +3 -5
- data/README.md +0 -1
- data/lib/triad/version.rb +1 -1
- data/lib/triad.rb +22 -14
- data/test/triad_test.rb +37 -3
- data/triad.gemspec +2 -5
- metadata +7 -41
- data/.gitignore +0 -17
- data/.travis.yml +0 -16
- data/test/test_helper.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1506f956e5cf2624d48a561a54b55e6a421bd92f5542004eec34df90ebb814a7
|
4
|
+
data.tar.gz: a090e6814e78240b6081e7e5d6c730751d451c07411d01b9b6149cd84bd00d4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d26ec61656145fcedc646b5dafdf0a1cff341cb74e9bee9592d99ed62d1db7e118ec9ed9e791dd85e96cdd7a3192a210a9763476f36d9e3f9cb7f7ee1b74b81
|
7
|
+
data.tar.gz: 7035ae759c39fd4b1abf78a63b3637d84d69f2dddb0b835e056e49a1a69727e98eb2e37d588f2e24e53fd004e244289d4c3bca562ae689da3e5bb0f23da986b5
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# Triad
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.org/saturnflyer/triad.png?branch=master)](https://travis-ci.org/saturnflyer/triad)
|
4
3
|
[![Code Climate](https://codeclimate.com/github/saturnflyer/triad.png)](https://codeclimate.com/github/saturnflyer/triad)
|
5
4
|
[![Coverage Status](https://coveralls.io/repos/saturnflyer/triad/badge.png)](https://coveralls.io/r/saturnflyer/triad)
|
6
5
|
[![Gem Version](https://badge.fury.io/rb/triad.png)](http://badge.fury.io/rb/triad)
|
data/lib/triad/version.rb
CHANGED
data/lib/triad.rb
CHANGED
@@ -14,22 +14,25 @@ class Triad
|
|
14
14
|
attr_reader :storage
|
15
15
|
private :storage
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
# Return the keys for a given descriptor or value
|
18
|
+
def keys(arg=nil)
|
19
|
+
if arg == nil
|
19
20
|
storage.keys
|
20
21
|
else
|
21
22
|
with_interest(arg).map{|key, _, _| key }
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
25
|
-
|
26
|
-
|
26
|
+
# Return the descriptors for a given key or value
|
27
|
+
def descriptors(arg=nil)
|
28
|
+
if arg.nil?
|
27
29
|
storage.map{|_,(descriptor,_)| descriptor }
|
28
30
|
else
|
29
31
|
with_interest(arg).map{|_, descriptor, _| descriptor }
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
35
|
+
# Return the values for a given key or descriptor
|
33
36
|
def values(arg=:__no_argument_given__)
|
34
37
|
if arg == :__no_argument_given__
|
35
38
|
storage.map{|_,(_,value)| value }.uniq
|
@@ -38,40 +41,45 @@ class Triad
|
|
38
41
|
end
|
39
42
|
end
|
40
43
|
|
44
|
+
# Add new entries to the object
|
41
45
|
def <<(array)
|
42
|
-
array_key = array[0]
|
43
46
|
raise InvalidAddition.new("your array length must be 3") if array.length != 3
|
47
|
+
array_key = array.fetch(0)
|
48
|
+
raise InvalidAddition.new("the provided key must be a Symbol") unless array_key.is_a?(Symbol)
|
44
49
|
raise InvalidAddition.new("the provided key already exists") if key_exists?(array_key)
|
45
50
|
|
46
|
-
array_descriptor = array
|
47
|
-
|
51
|
+
array_descriptor = array.fetch(1)
|
52
|
+
raise InvalidAddition.new("the provided descriptor must be a String") unless array_descriptor.is_a?(String)
|
53
|
+
array_value = array.fetch(2)
|
48
54
|
|
49
55
|
storage[array_key] = [array_descriptor, array_value]
|
50
56
|
self
|
51
57
|
end
|
52
58
|
|
59
|
+
# Alter the descriptor and value in-place for the given key
|
53
60
|
def update(key, descriptor, value)
|
61
|
+
raise InvalidAddition.new("the provided descriptor cannot be nil") if descriptor.nil?
|
54
62
|
storage[key] = [descriptor, value]
|
55
63
|
end
|
56
64
|
|
57
|
-
def each
|
65
|
+
def each
|
58
66
|
storage.each do |key, (descriptor, value)|
|
59
|
-
|
67
|
+
yield key, descriptor, value
|
60
68
|
end
|
61
69
|
end
|
62
70
|
|
63
71
|
private
|
64
72
|
|
65
73
|
def key_exists?(key)
|
66
|
-
storage.
|
74
|
+
storage.key?(key)
|
67
75
|
end
|
68
|
-
|
76
|
+
|
69
77
|
def descriptor_exists?(descriptor)
|
70
|
-
storage.values.map{|arr| arr
|
78
|
+
storage.values.map{|arr| arr.fetch(0) }.include?(descriptor)
|
71
79
|
end
|
72
|
-
|
80
|
+
|
73
81
|
def value_exists?(value)
|
74
|
-
storage.values.map{|arr| arr
|
82
|
+
storage.values.map{|arr| arr.fetch(1) }.include?(value)
|
75
83
|
end
|
76
84
|
|
77
85
|
def with_interest(interest)
|
data/test/triad_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative 'test_helper'
|
2
2
|
|
3
3
|
describe Triad, '#<<' do
|
4
4
|
let(:triad){ Triad.new }
|
@@ -22,9 +22,10 @@ describe Triad, '#<<' do
|
|
22
22
|
|
23
23
|
it 'rejects arrays with an existing key' do
|
24
24
|
triad << [:test, 'Test', Object.new]
|
25
|
-
assert_raises(Triad::InvalidAddition){
|
25
|
+
error = assert_raises(Triad::InvalidAddition){
|
26
26
|
triad << [:test, 'More', Object.new]
|
27
27
|
}
|
28
|
+
assert_match(/key already exists/, error.message)
|
28
29
|
end
|
29
30
|
|
30
31
|
it 'accepts strings as values' do
|
@@ -32,6 +33,20 @@ describe Triad, '#<<' do
|
|
32
33
|
triad << [:key, 'Descriptor', object]
|
33
34
|
assert_equal [object], triad.values(:key)
|
34
35
|
end
|
36
|
+
|
37
|
+
it "rejects keys that are not Symbols" do
|
38
|
+
error = assert_raises(Triad::InvalidAddition){
|
39
|
+
triad << ["key", "Descriptor", Object.new]
|
40
|
+
}
|
41
|
+
assert_match(/must be a Symbol/, error.message)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "rejects descriptors that are not Strings" do
|
45
|
+
error = assert_raises(Triad::InvalidAddition){
|
46
|
+
triad << [:key, :Descriptor, Object.new]
|
47
|
+
}
|
48
|
+
assert_match(/must be a String/, error.message)
|
49
|
+
end
|
35
50
|
end
|
36
51
|
|
37
52
|
describe Triad, '#update' do
|
@@ -44,6 +59,20 @@ describe Triad, '#update' do
|
|
44
59
|
triad.update(:test, 'Updated', Object.new)
|
45
60
|
assert_equal ['Updated'], triad.descriptors(:test)
|
46
61
|
end
|
62
|
+
|
63
|
+
it "allows a nil object" do
|
64
|
+
triad << [:test, 'Test', nil]
|
65
|
+
assert_equal ['Test'], triad.descriptors(:test)
|
66
|
+
triad.update(:test, 'Updated', nil)
|
67
|
+
assert_equal ['Updated'], triad.descriptors(:test)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "does not allow a nil descriptor" do
|
71
|
+
err = assert_raises(Triad::InvalidAddition){
|
72
|
+
triad.update(:test, nil, Object.new)
|
73
|
+
}
|
74
|
+
assert_equal "the provided descriptor cannot be nil", err.message
|
75
|
+
end
|
47
76
|
end
|
48
77
|
|
49
78
|
describe Triad, '#keys' do
|
@@ -132,6 +161,11 @@ describe Triad, '#descriptors' do
|
|
132
161
|
triad.descriptors(Object.new)
|
133
162
|
}
|
134
163
|
end
|
164
|
+
|
165
|
+
it 'assumes nil is a value' do
|
166
|
+
triad.update(:admin, 'Admin', nil)
|
167
|
+
assert_equal ['Admin'], triad.descriptors(:admin)
|
168
|
+
end
|
135
169
|
end
|
136
170
|
|
137
171
|
describe Triad, '#values' do
|
@@ -183,4 +217,4 @@ describe Triad, 'enumeration' do
|
|
183
217
|
end
|
184
218
|
assert_equal 'key: admin, descriptor: Admin, value: Object', result
|
185
219
|
end
|
186
|
-
end
|
220
|
+
end
|
data/triad.gemspec
CHANGED
@@ -10,16 +10,13 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["jim@saturnflyer.com"]
|
11
11
|
spec.description = %q{Triad allows you to access data from keys, descriptors, and values}
|
12
12
|
spec.summary = %q{Manage a collection with 3 data points}
|
13
|
-
spec.homepage = ""
|
13
|
+
spec.homepage = "https://github.com/saturnflyer/triad"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
|
-
spec.files =
|
16
|
+
spec.files = Dir['lib/**/*'] + %w[ Gemfile LICENSE.txt README.md Rakefile triad.gemspec test/triad_test.rb ]
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_dependency "concurrent-ruby", "> 0.9"
|
22
|
-
|
23
|
-
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
-
spec.add_development_dependency "rake"
|
25
22
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: triad
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "'Jim Gay'"
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -24,34 +24,6 @@ dependencies:
|
|
24
24
|
- - ">"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.9'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: bundler
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '1.3'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '1.3'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
27
|
description: Triad allows you to access data from keys, descriptors, and values
|
56
28
|
email:
|
57
29
|
- jim@saturnflyer.com
|
@@ -59,22 +31,19 @@ executables: []
|
|
59
31
|
extensions: []
|
60
32
|
extra_rdoc_files: []
|
61
33
|
files:
|
62
|
-
- ".gitignore"
|
63
|
-
- ".travis.yml"
|
64
34
|
- Gemfile
|
65
35
|
- LICENSE.txt
|
66
36
|
- README.md
|
67
37
|
- Rakefile
|
68
38
|
- lib/triad.rb
|
69
39
|
- lib/triad/version.rb
|
70
|
-
- test/test_helper.rb
|
71
40
|
- test/triad_test.rb
|
72
41
|
- triad.gemspec
|
73
|
-
homepage:
|
42
|
+
homepage: https://github.com/saturnflyer/triad
|
74
43
|
licenses:
|
75
44
|
- MIT
|
76
45
|
metadata: {}
|
77
|
-
post_install_message:
|
46
|
+
post_install_message:
|
78
47
|
rdoc_options: []
|
79
48
|
require_paths:
|
80
49
|
- lib
|
@@ -89,12 +58,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
58
|
- !ruby/object:Gem::Version
|
90
59
|
version: '0'
|
91
60
|
requirements: []
|
92
|
-
|
93
|
-
|
94
|
-
signing_key:
|
61
|
+
rubygems_version: 3.3.17
|
62
|
+
signing_key:
|
95
63
|
specification_version: 4
|
96
64
|
summary: Manage a collection with 3 data points
|
97
65
|
test_files:
|
98
|
-
- test/test_helper.rb
|
99
66
|
- test/triad_test.rb
|
100
|
-
has_rdoc:
|
data/.gitignore
DELETED
data/.travis.yml
DELETED