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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c509af042f22f2fb764c0d6218b0ed45d0cce53d
4
- data.tar.gz: 5958c9b4e43aeba09e4956393918730a30c25189
2
+ SHA256:
3
+ metadata.gz: 1506f956e5cf2624d48a561a54b55e6a421bd92f5542004eec34df90ebb814a7
4
+ data.tar.gz: a090e6814e78240b6081e7e5d6c730751d451c07411d01b9b6149cd84bd00d4e
5
5
  SHA512:
6
- metadata.gz: 0bc285d97ec8e4f1418d27f53d5cec3822faf793e32a45871cbc2e84e6e403ddb01756864f56eb1d007555871dd10a03f0c7dc1d4bf88e9d247dd25fd3c58f18
7
- data.tar.gz: e3f7700cc6f6410994b627c05a573c219df2ba41e055f99452a64499b98cb476a637be78bc674d6fe2adbad43d6b2a053cefa2a045fecfe1972b5ccdb26658c4
6
+ metadata.gz: 2d26ec61656145fcedc646b5dafdf0a1cff341cb74e9bee9592d99ed62d1db7e118ec9ed9e791dd85e96cdd7a3192a210a9763476f36d9e3f9cb7f7ee1b74b81
7
+ data.tar.gz: 7035ae759c39fd4b1abf78a63b3637d84d69f2dddb0b835e056e49a1a69727e98eb2e37d588f2e24e53fd004e244289d4c3bca562ae689da3e5bb0f23da986b5
data/Gemfile CHANGED
@@ -2,8 +2,6 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- group :test do
6
- gem "simplecov"
7
- gem "minitest"
8
- gem "coveralls"
9
- end
5
+ gem "rake"
6
+ gem "simplecov"
7
+ gem "minitest"
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
@@ -1,3 +1,3 @@
1
1
  class Triad
2
- VERSION = "0.3.0"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/triad.rb CHANGED
@@ -14,22 +14,25 @@ class Triad
14
14
  attr_reader :storage
15
15
  private :storage
16
16
 
17
- def keys(arg=:__no_argument_given__)
18
- if arg == :__no_argument_given__
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
- def descriptors(arg=:__no_argument_given__)
26
- if arg == :__no_argument_given__
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[1]
47
- array_value = array[2]
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(&block)
65
+ def each
58
66
  storage.each do |key, (descriptor, value)|
59
- block.call key, descriptor, value
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.has_key?(key)
74
+ storage.key?(key)
67
75
  end
68
-
76
+
69
77
  def descriptor_exists?(descriptor)
70
- storage.values.map{|arr| arr[0] }.include?(descriptor)
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[1] }.include?(value)
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
- require 'test_helper'
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 = `git ls-files`.split($/)
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.3.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: 2016-06-07 00:00:00.000000000 Z
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
- rubyforge_project:
93
- rubygems_version: 2.5.1
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
@@ -1,17 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
data/.travis.yml DELETED
@@ -1,16 +0,0 @@
1
- before_install:
2
- - gem install bundler
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.3.1
7
- - 2.2.5
8
- - 2.1.10
9
- - ruby-head
10
- - jruby-head
11
- env:
12
- - COVERALLS=true
13
- matrix:
14
- allow_failures:
15
- - rvm: ruby-head
16
- - rvm: jruby-head
data/test/test_helper.rb DELETED
@@ -1,13 +0,0 @@
1
- require 'simplecov'
2
- SimpleCov.start do
3
- add_filter 'test'
4
- end
5
- require 'coveralls'
6
-
7
- if ENV['COVERALLS']
8
- Coveralls.wear!
9
- end
10
-
11
- require 'minitest/autorun'
12
-
13
- require 'triad'