curio 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -1
- data/.travis.yml +8 -2
- data/{LICENSE.txt → LICENSE} +0 -0
- data/Rakefile +1 -2
- data/curio.gemspec +15 -10
- data/lib/curio.rb +27 -3
- data/lib/curio/version.rb +2 -1
- data/test/integration_test.rb +36 -3
- metadata +33 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c463ca337476e67d29b326574fc74a24d6d59db7
|
4
|
+
data.tar.gz: 27f5fc7a322dc4856df2978073fd8fb5c26afeaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd25cca619fef69396c93a0baa7815f3748cf9e95d6c173b29519bd1fafbcdec5c5fde1a6d1435327abd4cde37bba1b5ef665cc2330ef04df678cbeee7522190
|
7
|
+
data.tar.gz: a284eea87ad452f86bbcafd2eb909bc39877bb96ac71be8acfadb040c3507aebcc9629b6a3991aa43848a6ddb516d70950173ef4ea6b38b33fd8c9589000707d
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
@@ -1,8 +1,14 @@
|
|
1
1
|
language: ruby
|
2
|
-
script: 'bundle exec rake ci'
|
3
2
|
rvm:
|
4
3
|
- 1.9.3
|
5
4
|
- 2.0.0
|
6
|
-
- 2.1.
|
5
|
+
- 2.1.0
|
6
|
+
- 2.2.2
|
7
7
|
- jruby-19mode
|
8
8
|
- rbx-2
|
9
|
+
before_install:
|
10
|
+
- gem update --system
|
11
|
+
- gem update bundler
|
12
|
+
install: 'bundle install'
|
13
|
+
script: 'bundle exec rake'
|
14
|
+
cache: bundler
|
data/{LICENSE.txt → LICENSE}
RENAMED
File without changes
|
data/Rakefile
CHANGED
data/curio.gemspec
CHANGED
@@ -1,22 +1,27 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
|
3
|
-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'curio/version'
|
4
5
|
|
5
6
|
Gem::Specification.new do |spec|
|
6
7
|
spec.name = 'curio'
|
7
8
|
spec.version = Curio::VERSION
|
8
9
|
spec.authors = ['Terje Larsen']
|
9
10
|
spec.email = ['terlar@gmail.com']
|
10
|
-
spec.
|
11
|
-
spec.
|
11
|
+
spec.summary = 'Mixin for enumerable maps'
|
12
|
+
spec.description = spec.summary
|
12
13
|
spec.homepage = 'https://github.com/terlar/curio'
|
13
14
|
spec.license = 'MIT'
|
14
15
|
|
15
|
-
spec.files
|
16
|
-
spec.test_files
|
17
|
-
spec.require_paths
|
16
|
+
spec.files = `git ls-files`.split($RS)
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = %w(lib)
|
19
|
+
spec.extra_rdoc_files = %w(LICENSE README.md)
|
20
|
+
|
21
|
+
spec.required_ruby_version = '>= 1.9.3'
|
18
22
|
|
19
|
-
spec.add_development_dependency 'bundler'
|
20
|
-
spec.add_development_dependency 'rake'
|
21
|
-
spec.add_development_dependency '
|
23
|
+
spec.add_development_dependency 'bundler'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
spec.add_development_dependency 'minitest', '~> 5.8'
|
26
|
+
spec.add_development_dependency 'rubocop', '~> 0.35'
|
22
27
|
end
|
data/lib/curio.rb
CHANGED
@@ -29,7 +29,8 @@ class Curio < Module
|
|
29
29
|
#
|
30
30
|
# @api private
|
31
31
|
def initialize(key, type = String)
|
32
|
-
@key
|
32
|
+
@key = key
|
33
|
+
@type = type
|
33
34
|
|
34
35
|
define_key_method
|
35
36
|
define_coerce_key_method
|
@@ -130,11 +131,12 @@ class Curio < Module
|
|
130
131
|
# @return [self]
|
131
132
|
#
|
132
133
|
# @api public
|
133
|
-
def
|
134
|
+
def add(item)
|
134
135
|
key = coerce_key item.send(key_method)
|
135
|
-
@map[key] = item
|
136
|
+
@map[key.freeze] = item
|
136
137
|
self
|
137
138
|
end
|
139
|
+
alias_method :<<, :add
|
138
140
|
|
139
141
|
# Fetch an item from the collection
|
140
142
|
#
|
@@ -184,5 +186,27 @@ class Curio < Module
|
|
184
186
|
def to_h
|
185
187
|
@map
|
186
188
|
end
|
189
|
+
|
190
|
+
# Set map source
|
191
|
+
#
|
192
|
+
# @param [Hash] hash
|
193
|
+
#
|
194
|
+
# @return [Hash]
|
195
|
+
#
|
196
|
+
# @api public
|
197
|
+
def map=(hash)
|
198
|
+
@map = hash
|
199
|
+
end
|
200
|
+
|
201
|
+
# Freeze map and items
|
202
|
+
#
|
203
|
+
# @return [self]
|
204
|
+
#
|
205
|
+
# @api public
|
206
|
+
def freeze
|
207
|
+
@map.values.each(&:freeze)
|
208
|
+
@map.freeze
|
209
|
+
super
|
210
|
+
end
|
187
211
|
end
|
188
212
|
end
|
data/lib/curio/version.rb
CHANGED
data/test/integration_test.rb
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
|
3
3
|
require_relative 'test_helper'
|
4
4
|
|
5
|
-
|
5
|
+
# rubocop: disable ClassLength
|
6
|
+
class IntegrationTest < Minitest::Test
|
6
7
|
class Collection
|
7
8
|
include Curio.new(:id)
|
8
9
|
end
|
@@ -66,6 +67,15 @@ class IntegrationTest < MiniTest::Unit::TestCase
|
|
66
67
|
def test_adding_an_item
|
67
68
|
item = Item.new 1
|
68
69
|
|
70
|
+
assert_equal 0, collection.count
|
71
|
+
collection.add item
|
72
|
+
assert_includes collection, item
|
73
|
+
assert_equal 1, collection.count
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_adding_an_item_with_shovel_operator
|
77
|
+
item = Item.new 1
|
78
|
+
|
69
79
|
assert_equal 0, collection.count
|
70
80
|
collection << item
|
71
81
|
assert_includes collection, item
|
@@ -73,8 +83,7 @@ class IntegrationTest < MiniTest::Unit::TestCase
|
|
73
83
|
end
|
74
84
|
|
75
85
|
def test_item_is_known
|
76
|
-
|
77
|
-
collection << item
|
86
|
+
collection << Item.new('a')
|
78
87
|
|
79
88
|
assert collection.key? 'a'
|
80
89
|
assert collection.has? 'a'
|
@@ -103,4 +112,28 @@ class IntegrationTest < MiniTest::Unit::TestCase
|
|
103
112
|
found = collection.fetch :'1'
|
104
113
|
assert_equal item, found
|
105
114
|
end
|
115
|
+
|
116
|
+
def test_change_map_source
|
117
|
+
other_map = { }
|
118
|
+
|
119
|
+
collection.map = other_map
|
120
|
+
collection << Item.new(1)
|
121
|
+
|
122
|
+
assert_equal collection.to_h, other_map
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_supports_freeze
|
126
|
+
collection.freeze
|
127
|
+
|
128
|
+
assert collection.frozen?
|
129
|
+
assert collection.to_h.frozen?
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_freeze_freezes_items
|
133
|
+
collection << Item.new(1)
|
134
|
+
collection.freeze
|
135
|
+
|
136
|
+
assert collection.first.frozen?
|
137
|
+
end
|
106
138
|
end
|
139
|
+
# rubocop: enable ClassLength
|
metadata
CHANGED
@@ -1,69 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: curio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Terje Larsen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
31
|
- - "~>"
|
18
32
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
33
|
+
version: '10.0'
|
20
34
|
type: :development
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
24
38
|
- - "~>"
|
25
39
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
40
|
+
version: '10.0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
42
|
+
name: minitest
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- - "
|
45
|
+
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
47
|
+
version: '5.8'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- - "
|
52
|
+
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
54
|
+
version: '5.8'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rubocop
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- - "
|
59
|
+
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
61
|
+
version: '0.35'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
|
-
- - "
|
66
|
+
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
68
|
+
version: '0.35'
|
55
69
|
description: Mixin for enumerable maps
|
56
70
|
email:
|
57
71
|
- terlar@gmail.com
|
58
72
|
executables: []
|
59
73
|
extensions: []
|
60
|
-
extra_rdoc_files:
|
74
|
+
extra_rdoc_files:
|
75
|
+
- LICENSE
|
76
|
+
- README.md
|
61
77
|
files:
|
62
78
|
- ".gitignore"
|
63
79
|
- ".rubocop.yml"
|
64
80
|
- ".travis.yml"
|
65
81
|
- Gemfile
|
66
|
-
- LICENSE
|
82
|
+
- LICENSE
|
67
83
|
- README.md
|
68
84
|
- Rakefile
|
69
85
|
- curio.gemspec
|
@@ -83,7 +99,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
83
99
|
requirements:
|
84
100
|
- - ">="
|
85
101
|
- !ruby/object:Gem::Version
|
86
|
-
version:
|
102
|
+
version: 1.9.3
|
87
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
104
|
requirements:
|
89
105
|
- - ">="
|
@@ -91,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
107
|
version: '0'
|
92
108
|
requirements: []
|
93
109
|
rubyforge_project:
|
94
|
-
rubygems_version: 2.
|
110
|
+
rubygems_version: 2.4.5.1
|
95
111
|
signing_key:
|
96
112
|
specification_version: 4
|
97
113
|
summary: Mixin for enumerable maps
|