triad 0.3.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/Gemfile +6 -6
- data/LICENSE.txt +1 -1
- data/README.md +0 -3
- data/Rakefile +17 -4
- data/lib/triad/version.rb +1 -1
- data/lib/triad.rb +74 -37
- data/test/triad_test.rb +118 -85
- data/triad.gemspec +12 -17
- metadata +5 -43
- 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: 8d4039aff99f0f7377d3c23e7f634497f2e0af40493a9e4da202b5f73d1746e3
|
|
4
|
+
data.tar.gz: 468e03146649a0fff076569e5d659942f78af0d1aee15e825f3469f1de580eb5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c9280599c5af2e49ebace1860b3492a0c0dffc0b3a7bc93b0ae335c359f825c35ce602d1030c279e67da2ee89d4261bed26474343d4fb8b385de2527166d3a59
|
|
7
|
+
data.tar.gz: 5c8fcaec38453c0ffa91c1d14952c7d963aa45076bfb1ae0f36542ee873a30852028f3a965b3b0725aa08f13e2e711c5948831bd16138f3b0de7d3ee31d6a7aa
|
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
# Triad
|
|
2
2
|
|
|
3
|
-
[](https://travis-ci.org/saturnflyer/triad)
|
|
4
|
-
[](https://codeclimate.com/github/saturnflyer/triad)
|
|
5
|
-
[](https://coveralls.io/r/saturnflyer/triad)
|
|
6
3
|
[](http://badge.fury.io/rb/triad)
|
|
7
4
|
|
|
8
5
|
A Triad is like a Set, or a collection of three-part arrays.
|
data/Rakefile
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
#!/usr/bin/env rake
|
|
2
2
|
require "bundler/gem_tasks"
|
|
3
|
-
require
|
|
3
|
+
require "rake/testtask"
|
|
4
4
|
|
|
5
5
|
Rake::TestTask.new do |t|
|
|
6
|
-
t.libs <<
|
|
7
|
-
t.test_files = FileList[
|
|
6
|
+
t.libs << "test"
|
|
7
|
+
t.test_files = FileList["test/*_test.rb"]
|
|
8
8
|
t.ruby_opts = ["-w"]
|
|
9
9
|
t.verbose = true
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
# Configure Reissue for automated versioning and changelog management
|
|
13
|
+
require "reissue/gem"
|
|
14
|
+
|
|
15
|
+
Reissue::Task.create :reissue do |task|
|
|
16
|
+
task.version_file = "lib/triad/version.rb"
|
|
17
|
+
task.changelog_file = "CHANGELOG.md"
|
|
18
|
+
task.version_limit = 2
|
|
19
|
+
task.commit = true
|
|
20
|
+
task.commit_finalize = true
|
|
21
|
+
task.push_finalize = true
|
|
22
|
+
task.fragment = :git
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
task default: :test
|
data/lib/triad/version.rb
CHANGED
data/lib/triad.rb
CHANGED
|
@@ -5,86 +5,123 @@ class Triad
|
|
|
5
5
|
include Enumerable
|
|
6
6
|
|
|
7
7
|
class InvalidAddition < StandardError; end
|
|
8
|
+
|
|
8
9
|
class ItemNotPresent < StandardError; end
|
|
9
10
|
|
|
10
|
-
# stored as {key =>
|
|
11
|
+
# stored as {key => {descriptor: 'Descriptor', value: value}}
|
|
11
12
|
def initialize
|
|
12
13
|
@storage = Concurrent::Hash.new
|
|
14
|
+
@descriptor_index = Concurrent::Hash.new
|
|
15
|
+
@value_index = Concurrent::Hash.new
|
|
13
16
|
end
|
|
14
|
-
attr_reader :storage
|
|
15
|
-
private :storage
|
|
17
|
+
attr_reader :storage, :descriptor_index, :value_index
|
|
18
|
+
private :storage, :descriptor_index, :value_index
|
|
16
19
|
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
# Return the keys for a given descriptor or value
|
|
21
|
+
def keys(arg = nil)
|
|
22
|
+
if arg.nil?
|
|
19
23
|
storage.keys
|
|
20
24
|
else
|
|
21
|
-
with_interest(arg).map{|key, _, _| key }
|
|
25
|
+
with_interest(arg).map { |key, _, _| key }
|
|
22
26
|
end
|
|
23
27
|
end
|
|
24
28
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
# Return the descriptors for a given key or value
|
|
30
|
+
def descriptors(arg = nil)
|
|
31
|
+
if arg.nil?
|
|
32
|
+
storage.map { |_, data| data[:descriptor] }
|
|
28
33
|
else
|
|
29
|
-
with_interest(arg).map{|_, descriptor, _| descriptor }
|
|
34
|
+
with_interest(arg).map { |_, descriptor, _| descriptor }
|
|
30
35
|
end
|
|
31
36
|
end
|
|
32
37
|
|
|
33
|
-
|
|
38
|
+
# Return the values for a given key or descriptor
|
|
39
|
+
def values(arg = :__no_argument_given__)
|
|
34
40
|
if arg == :__no_argument_given__
|
|
35
|
-
|
|
41
|
+
value_index.keys
|
|
36
42
|
else
|
|
37
|
-
with_interest(arg).map{|_, _, value| value }
|
|
43
|
+
with_interest(arg).map { |_, _, value| value }
|
|
38
44
|
end
|
|
39
45
|
end
|
|
40
46
|
|
|
47
|
+
# Add new entries to the object
|
|
41
48
|
def <<(array)
|
|
42
|
-
array_key = array[0]
|
|
43
49
|
raise InvalidAddition.new("your array length must be 3") if array.length != 3
|
|
50
|
+
array_key = array.fetch(0)
|
|
51
|
+
raise InvalidAddition.new("the provided key must be a Symbol") unless array_key.is_a?(Symbol)
|
|
44
52
|
raise InvalidAddition.new("the provided key already exists") if key_exists?(array_key)
|
|
45
53
|
|
|
46
|
-
array_descriptor = array
|
|
47
|
-
|
|
54
|
+
array_descriptor = array.fetch(1)
|
|
55
|
+
raise InvalidAddition.new("the provided descriptor must be a String") unless array_descriptor.is_a?(String)
|
|
56
|
+
array_value = array.fetch(2)
|
|
48
57
|
|
|
49
|
-
|
|
58
|
+
add_to_storage(array_key, array_descriptor, array_value)
|
|
50
59
|
self
|
|
51
60
|
end
|
|
52
61
|
|
|
62
|
+
# Alter the descriptor and value in-place for the given key
|
|
53
63
|
def update(key, descriptor, value)
|
|
54
|
-
|
|
64
|
+
raise InvalidAddition.new("the provided descriptor cannot be nil") if descriptor.nil?
|
|
65
|
+
remove_from_indices(key) if storage.key?(key)
|
|
66
|
+
add_to_storage(key, descriptor, value)
|
|
55
67
|
end
|
|
56
68
|
|
|
57
|
-
def each
|
|
58
|
-
storage.each do |key,
|
|
59
|
-
|
|
69
|
+
def each
|
|
70
|
+
storage.each do |key, data|
|
|
71
|
+
yield key, data[:descriptor], data[:value]
|
|
60
72
|
end
|
|
61
73
|
end
|
|
62
74
|
|
|
63
75
|
private
|
|
64
76
|
|
|
77
|
+
def add_to_storage(key, descriptor, value)
|
|
78
|
+
storage[key] = { descriptor: descriptor, value: value }
|
|
79
|
+
descriptor_index[descriptor] = (descriptor_index[descriptor] || []) << key
|
|
80
|
+
value_index[value] = (value_index[value] || []) << key
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def remove_from_indices(key)
|
|
84
|
+
return unless storage.key?(key)
|
|
85
|
+
|
|
86
|
+
data = storage[key]
|
|
87
|
+
descriptor = data[:descriptor]
|
|
88
|
+
value = data[:value]
|
|
89
|
+
|
|
90
|
+
descriptor_index[descriptor]&.delete(key)
|
|
91
|
+
descriptor_index.delete(descriptor) if descriptor_index[descriptor]&.empty?
|
|
92
|
+
|
|
93
|
+
value_index[value]&.delete(key)
|
|
94
|
+
value_index.delete(value) if value_index[value]&.empty?
|
|
95
|
+
end
|
|
96
|
+
|
|
65
97
|
def key_exists?(key)
|
|
66
|
-
storage.
|
|
98
|
+
storage.key?(key)
|
|
67
99
|
end
|
|
68
|
-
|
|
100
|
+
|
|
69
101
|
def descriptor_exists?(descriptor)
|
|
70
|
-
|
|
102
|
+
descriptor_index.key?(descriptor)
|
|
71
103
|
end
|
|
72
|
-
|
|
104
|
+
|
|
73
105
|
def value_exists?(value)
|
|
74
|
-
|
|
106
|
+
value_index.key?(value)
|
|
75
107
|
end
|
|
76
108
|
|
|
77
109
|
def with_interest(interest)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
[
|
|
88
|
-
|
|
110
|
+
if key_exists?(interest)
|
|
111
|
+
data = storage[interest]
|
|
112
|
+
[[interest, data[:descriptor], data[:value]]]
|
|
113
|
+
elsif descriptor_exists?(interest)
|
|
114
|
+
descriptor_index[interest].map do |key|
|
|
115
|
+
data = storage[key]
|
|
116
|
+
[key, data[:descriptor], data[:value]]
|
|
117
|
+
end
|
|
118
|
+
elsif value_exists?(interest)
|
|
119
|
+
value_index[interest].map do |key|
|
|
120
|
+
data = storage[key]
|
|
121
|
+
[key, data[:descriptor], data[:value]]
|
|
122
|
+
end
|
|
123
|
+
else
|
|
124
|
+
raise ItemNotPresent.new
|
|
125
|
+
end
|
|
89
126
|
end
|
|
90
127
|
end
|
data/test/triad_test.rb
CHANGED
|
@@ -1,186 +1,219 @@
|
|
|
1
|
-
|
|
1
|
+
require_relative "test_helper"
|
|
2
2
|
|
|
3
|
-
describe Triad,
|
|
4
|
-
let(:triad){ Triad.new }
|
|
3
|
+
describe Triad, "#<<" do
|
|
4
|
+
let(:triad) { Triad.new }
|
|
5
5
|
|
|
6
|
-
it
|
|
7
|
-
assert triad << [:test,
|
|
6
|
+
it "shovels 3 item arrays" do
|
|
7
|
+
assert triad << [:test, "Test", Object.new]
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
it
|
|
11
|
-
error = assert_raises(Triad::InvalidAddition){
|
|
12
|
-
triad << [:test,
|
|
10
|
+
it "rejects arrays with more than 3 items" do
|
|
11
|
+
error = assert_raises(Triad::InvalidAddition) {
|
|
12
|
+
triad << [:test, "Test", Object.new, "Other"]
|
|
13
13
|
}
|
|
14
14
|
assert_match(/array length must be 3/, error.message)
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
it
|
|
18
|
-
assert_raises(Triad::InvalidAddition){
|
|
19
|
-
triad << [:test,
|
|
17
|
+
it "rejects arrays with fewer than 3 items" do
|
|
18
|
+
assert_raises(Triad::InvalidAddition) {
|
|
19
|
+
triad << [:test, "Test"]
|
|
20
20
|
}
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
it
|
|
24
|
-
triad << [:test,
|
|
25
|
-
assert_raises(Triad::InvalidAddition){
|
|
26
|
-
triad << [:test,
|
|
23
|
+
it "rejects arrays with an existing key" do
|
|
24
|
+
triad << [:test, "Test", Object.new]
|
|
25
|
+
error = assert_raises(Triad::InvalidAddition) {
|
|
26
|
+
triad << [:test, "More", Object.new]
|
|
27
27
|
}
|
|
28
|
+
assert_match(/key already exists/, error.message)
|
|
28
29
|
end
|
|
29
|
-
|
|
30
|
-
it
|
|
30
|
+
|
|
31
|
+
it "accepts strings as values" do
|
|
31
32
|
object = "a string as an value"
|
|
32
|
-
triad << [:key,
|
|
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
|
-
describe Triad,
|
|
38
|
-
let(:triad){ Triad.new }
|
|
52
|
+
describe Triad, "#update" do
|
|
53
|
+
let(:triad) { Triad.new }
|
|
39
54
|
|
|
40
|
-
it
|
|
55
|
+
it "updates a descriptor and object for the given key" do
|
|
41
56
|
object = Object.new
|
|
42
|
-
triad << [:test,
|
|
43
|
-
assert_equal [
|
|
44
|
-
triad.update(:test,
|
|
45
|
-
assert_equal [
|
|
57
|
+
triad << [:test, "Test", object]
|
|
58
|
+
assert_equal ["Test"], triad.descriptors(:test)
|
|
59
|
+
triad.update(:test, "Updated", Object.new)
|
|
60
|
+
assert_equal ["Updated"], triad.descriptors(:test)
|
|
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
|
|
46
75
|
end
|
|
47
76
|
end
|
|
48
77
|
|
|
49
|
-
describe Triad,
|
|
50
|
-
let(:user){ Object.new }
|
|
51
|
-
let(:triad){
|
|
78
|
+
describe Triad, "#keys" do
|
|
79
|
+
let(:user) { Object.new }
|
|
80
|
+
let(:triad) {
|
|
52
81
|
tri = Triad.new
|
|
53
|
-
tri << [:admin,
|
|
82
|
+
tri << [:admin, "Admin", user]
|
|
54
83
|
tri
|
|
55
84
|
}
|
|
56
85
|
|
|
57
|
-
it
|
|
58
|
-
assert_equal [:admin], triad.keys(
|
|
86
|
+
it "returns the key for the given descriptor" do
|
|
87
|
+
assert_equal [:admin], triad.keys("Admin")
|
|
59
88
|
end
|
|
60
89
|
|
|
61
|
-
it
|
|
90
|
+
it "returns the key for the given value" do
|
|
62
91
|
assert_equal [:admin], triad.keys(user)
|
|
63
92
|
end
|
|
64
93
|
|
|
65
|
-
it
|
|
94
|
+
it "returns the keys for the given key" do
|
|
66
95
|
assert_equal [:admin], triad.keys(:admin)
|
|
67
96
|
end
|
|
68
97
|
|
|
69
|
-
it
|
|
70
|
-
triad << [:other,
|
|
98
|
+
it "returns all keys when given no argument" do
|
|
99
|
+
triad << [:other, "Other", user]
|
|
71
100
|
assert_equal [:admin, :other], triad.keys
|
|
72
101
|
end
|
|
73
102
|
|
|
74
|
-
it
|
|
75
|
-
assert_raises(Triad::ItemNotPresent){
|
|
103
|
+
it "errors when the given key is not found" do
|
|
104
|
+
assert_raises(Triad::ItemNotPresent) {
|
|
76
105
|
triad.keys(:invalid_key)
|
|
77
106
|
}
|
|
78
107
|
end
|
|
79
108
|
|
|
80
|
-
it
|
|
81
|
-
assert_raises(Triad::ItemNotPresent){
|
|
82
|
-
triad.keys(
|
|
109
|
+
it "errors when the given descriptor is not found" do
|
|
110
|
+
assert_raises(Triad::ItemNotPresent) {
|
|
111
|
+
triad.keys("Invalid Descriptor")
|
|
83
112
|
}
|
|
84
113
|
end
|
|
85
114
|
|
|
86
|
-
it
|
|
87
|
-
assert_raises(Triad::ItemNotPresent){
|
|
115
|
+
it "errors when the given value is not found" do
|
|
116
|
+
assert_raises(Triad::ItemNotPresent) {
|
|
88
117
|
triad.keys(Object.new)
|
|
89
118
|
}
|
|
90
119
|
end
|
|
91
120
|
end
|
|
92
121
|
|
|
93
|
-
describe Triad,
|
|
94
|
-
let(:user){ Object.new }
|
|
95
|
-
let(:triad){
|
|
122
|
+
describe Triad, "#descriptors" do
|
|
123
|
+
let(:user) { Object.new }
|
|
124
|
+
let(:triad) {
|
|
96
125
|
tri = Triad.new
|
|
97
|
-
tri << [:admin,
|
|
126
|
+
tri << [:admin, "Admin", user]
|
|
98
127
|
tri
|
|
99
128
|
}
|
|
100
129
|
|
|
101
|
-
it
|
|
102
|
-
assert_equal [
|
|
130
|
+
it "returns the descriptor for the given key" do
|
|
131
|
+
assert_equal ["Admin"], triad.descriptors(:admin)
|
|
103
132
|
end
|
|
104
133
|
|
|
105
|
-
it
|
|
106
|
-
assert_equal [
|
|
134
|
+
it "returns the descriptor for the given value" do
|
|
135
|
+
assert_equal ["Admin"], triad.descriptors(user)
|
|
107
136
|
end
|
|
108
137
|
|
|
109
|
-
it
|
|
110
|
-
assert_equal [
|
|
138
|
+
it "returns the descriptors for the given descriptor" do
|
|
139
|
+
assert_equal ["Admin"], triad.descriptors("Admin")
|
|
111
140
|
end
|
|
112
141
|
|
|
113
|
-
it
|
|
114
|
-
triad << [:other,
|
|
115
|
-
assert_equal [
|
|
142
|
+
it "returns all descriptors when given no argument" do
|
|
143
|
+
triad << [:other, "Other", user]
|
|
144
|
+
assert_equal ["Admin", "Other"], triad.descriptors
|
|
116
145
|
end
|
|
117
146
|
|
|
118
|
-
it
|
|
119
|
-
assert_raises(Triad::ItemNotPresent){
|
|
120
|
-
triad.descriptors(
|
|
147
|
+
it "errors when the given descriptor is not found" do
|
|
148
|
+
assert_raises(Triad::ItemNotPresent) {
|
|
149
|
+
triad.descriptors("Not Present")
|
|
121
150
|
}
|
|
122
151
|
end
|
|
123
152
|
|
|
124
|
-
it
|
|
125
|
-
assert_raises(Triad::ItemNotPresent){
|
|
153
|
+
it "errors when the given key is not found" do
|
|
154
|
+
assert_raises(Triad::ItemNotPresent) {
|
|
126
155
|
triad.descriptors(:invalid_key)
|
|
127
156
|
}
|
|
128
157
|
end
|
|
129
158
|
|
|
130
|
-
it
|
|
131
|
-
assert_raises(Triad::ItemNotPresent){
|
|
159
|
+
it "errors when the given value is not found" do
|
|
160
|
+
assert_raises(Triad::ItemNotPresent) {
|
|
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
|
-
describe Triad,
|
|
138
|
-
let(:user){ Object.new }
|
|
139
|
-
let(:triad){
|
|
171
|
+
describe Triad, "#values" do
|
|
172
|
+
let(:user) { Object.new }
|
|
173
|
+
let(:triad) {
|
|
140
174
|
tri = Triad.new
|
|
141
|
-
tri << [:admin,
|
|
175
|
+
tri << [:admin, "Admin", user]
|
|
142
176
|
tri
|
|
143
177
|
}
|
|
144
178
|
|
|
145
|
-
it
|
|
179
|
+
it "returns the value for the given key" do
|
|
146
180
|
assert_equal [user], triad.values(:admin)
|
|
147
181
|
end
|
|
148
182
|
|
|
149
|
-
it
|
|
150
|
-
assert_equal [user], triad.values(
|
|
183
|
+
it "returns the value for the given descriptor" do
|
|
184
|
+
assert_equal [user], triad.values("Admin")
|
|
151
185
|
end
|
|
152
186
|
|
|
153
|
-
it
|
|
154
|
-
triad << [:other,
|
|
187
|
+
it "returns all values when given no argument" do
|
|
188
|
+
triad << [:other, "Other", user]
|
|
155
189
|
assert_equal [user], triad.values
|
|
156
190
|
end
|
|
157
191
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
assert_raises(Triad::ItemNotPresent){
|
|
192
|
+
it "errors when the given key is not found" do
|
|
193
|
+
assert_raises(Triad::ItemNotPresent) {
|
|
161
194
|
triad.values(:invalid_key)
|
|
162
195
|
}
|
|
163
196
|
end
|
|
164
197
|
|
|
165
|
-
it
|
|
166
|
-
assert_raises(Triad::ItemNotPresent){
|
|
167
|
-
triad.values(
|
|
198
|
+
it "errors when the given descriptor is not found" do
|
|
199
|
+
assert_raises(Triad::ItemNotPresent) {
|
|
200
|
+
triad.values("Invalid Descriptor")
|
|
168
201
|
}
|
|
169
202
|
end
|
|
170
203
|
end
|
|
171
204
|
|
|
172
|
-
describe Triad,
|
|
173
|
-
let(:user){ Object.new }
|
|
174
|
-
let(:triad){
|
|
205
|
+
describe Triad, "enumeration" do
|
|
206
|
+
let(:user) { Object.new }
|
|
207
|
+
let(:triad) {
|
|
175
208
|
tri = Triad.new
|
|
176
|
-
tri << [:admin,
|
|
209
|
+
tri << [:admin, "Admin", user]
|
|
177
210
|
tri
|
|
178
211
|
}
|
|
179
|
-
it
|
|
180
|
-
result =
|
|
212
|
+
it "yields each triad as 3 block variables" do
|
|
213
|
+
result = ""
|
|
181
214
|
triad.each do |key, descriptor, value|
|
|
182
215
|
result << "key: #{key}, descriptor: #{descriptor}, value: #{value.class.name}"
|
|
183
216
|
end
|
|
184
|
-
assert_equal
|
|
217
|
+
assert_equal "key: admin, descriptor: Admin, value: Object", result
|
|
185
218
|
end
|
|
186
|
-
end
|
|
219
|
+
end
|
data/triad.gemspec
CHANGED
|
@@ -1,25 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
-
require
|
|
3
|
+
require "triad/version"
|
|
5
4
|
|
|
6
5
|
Gem::Specification.new do |spec|
|
|
7
|
-
spec.name
|
|
8
|
-
spec.version
|
|
9
|
-
spec.authors
|
|
10
|
-
spec.email
|
|
11
|
-
spec.description
|
|
12
|
-
spec.summary
|
|
13
|
-
spec.homepage
|
|
14
|
-
spec.license
|
|
6
|
+
spec.name = "triad"
|
|
7
|
+
spec.version = Triad::VERSION
|
|
8
|
+
spec.authors = ["'Jim Gay'"]
|
|
9
|
+
spec.email = ["jim@saturnflyer.com"]
|
|
10
|
+
spec.description = "Triad allows you to access data from keys, descriptors, and values"
|
|
11
|
+
spec.summary = "Manage a collection with 3 data points"
|
|
12
|
+
spec.homepage = "https://github.com/saturnflyer/triad"
|
|
13
|
+
spec.license = "MIT"
|
|
15
14
|
|
|
16
|
-
spec.files
|
|
17
|
-
spec.executables
|
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
15
|
+
spec.files = Dir["lib/**/*"] + %w[Gemfile LICENSE.txt README.md Rakefile triad.gemspec test/triad_test.rb]
|
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
19
17
|
spec.require_paths = ["lib"]
|
|
20
18
|
|
|
21
19
|
spec.add_dependency "concurrent-ruby", "> 0.9"
|
|
22
|
-
|
|
23
|
-
spec.add_development_dependency "bundler", "~> 1.3"
|
|
24
|
-
spec.add_development_dependency "rake"
|
|
25
20
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: triad
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- "'Jim Gay'"
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: concurrent-ruby
|
|
@@ -24,34 +23,6 @@ dependencies:
|
|
|
24
23
|
- - ">"
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
25
|
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
26
|
description: Triad allows you to access data from keys, descriptors, and values
|
|
56
27
|
email:
|
|
57
28
|
- jim@saturnflyer.com
|
|
@@ -59,22 +30,18 @@ executables: []
|
|
|
59
30
|
extensions: []
|
|
60
31
|
extra_rdoc_files: []
|
|
61
32
|
files:
|
|
62
|
-
- ".gitignore"
|
|
63
|
-
- ".travis.yml"
|
|
64
33
|
- Gemfile
|
|
65
34
|
- LICENSE.txt
|
|
66
35
|
- README.md
|
|
67
36
|
- Rakefile
|
|
68
37
|
- lib/triad.rb
|
|
69
38
|
- lib/triad/version.rb
|
|
70
|
-
- test/test_helper.rb
|
|
71
39
|
- test/triad_test.rb
|
|
72
40
|
- triad.gemspec
|
|
73
|
-
homepage:
|
|
41
|
+
homepage: https://github.com/saturnflyer/triad
|
|
74
42
|
licenses:
|
|
75
43
|
- MIT
|
|
76
44
|
metadata: {}
|
|
77
|
-
post_install_message:
|
|
78
45
|
rdoc_options: []
|
|
79
46
|
require_paths:
|
|
80
47
|
- lib
|
|
@@ -89,12 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
89
56
|
- !ruby/object:Gem::Version
|
|
90
57
|
version: '0'
|
|
91
58
|
requirements: []
|
|
92
|
-
|
|
93
|
-
rubygems_version: 2.5.1
|
|
94
|
-
signing_key:
|
|
59
|
+
rubygems_version: 3.7.2
|
|
95
60
|
specification_version: 4
|
|
96
61
|
summary: Manage a collection with 3 data points
|
|
97
|
-
test_files:
|
|
98
|
-
- test/test_helper.rb
|
|
99
|
-
- test/triad_test.rb
|
|
100
|
-
has_rdoc:
|
|
62
|
+
test_files: []
|
data/.gitignore
DELETED
data/.travis.yml
DELETED