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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7cd38a97f01363117f4f385112ba501751e369f1
4
- data.tar.gz: ae94e5f2c0fb34da902b1aabeebe4faaae6bd2c2
3
+ metadata.gz: c463ca337476e67d29b326574fc74a24d6d59db7
4
+ data.tar.gz: 27f5fc7a322dc4856df2978073fd8fb5c26afeaa
5
5
  SHA512:
6
- metadata.gz: f9cf6a715f7497990cd9fd15f0f50804b9f960dfbc6aca8ed01ebd1ec945a2d5d3acf8a7f43d2cfb3366a30de1e090826850b1c940fbce5d79d2a3c0e3eb176d
7
- data.tar.gz: f0d5db0de2a6163322cbc764e3f83f5bb1e74f19e6080faedcfe7d9c7a0ddf43c69607732915e87516e1f771c987d8985a08ecd79baa65e7abc02f500a44955a
6
+ metadata.gz: dd25cca619fef69396c93a0baa7815f3748cf9e95d6c173b29519bd1fafbcdec5c5fde1a6d1435327abd4cde37bba1b5ef665cc2330ef04df678cbeee7522190
7
+ data.tar.gz: a284eea87ad452f86bbcafd2eb909bc39877bb96ac71be8acfadb040c3507aebcc9629b6a3991aa43848a6ddb516d70950173ef4ea6b38b33fd8c9589000707d
data/.rubocop.yml CHANGED
@@ -8,7 +8,9 @@ Encoding:
8
8
  Enabled: true
9
9
 
10
10
  Documentation:
11
- Enabled: false
11
+ Enabled: true
12
+ Exclude:
13
+ - test/**/*
12
14
 
13
15
  LineLength:
14
16
  Max: 72
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.2
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
File without changes
data/Rakefile CHANGED
@@ -8,9 +8,8 @@ require 'rubocop/rake_task'
8
8
 
9
9
  RuboCop::RakeTask.new
10
10
 
11
- task default: :test
11
+ task default: %w(rubocop test)
12
12
  task test: 'test:all'
13
- task ci: %w(rubocop test:all)
14
13
 
15
14
  namespace :test do
16
15
  desc 'Run all tests'
data/curio.gemspec CHANGED
@@ -1,22 +1,27 @@
1
1
  # encoding: utf-8
2
-
3
- require File.expand_path('../lib/curio/version', __FILE__)
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.description = 'Mixin for enumerable maps'
11
- spec.summary = spec.description
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 = `git ls-files -z`.split("\x0")
16
- spec.test_files = spec.files.grep(/^test\//)
17
- spec.require_paths = ['lib']
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', '~> 1.6'
20
- spec.add_development_dependency 'rake'
21
- spec.add_development_dependency 'rubocop'
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, @type = key, type
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 <<(item)
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
@@ -1,5 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
+ # Version
3
4
  class Curio < Module
4
- VERSION = '0.1.1'
5
+ VERSION = '0.1.2'
5
6
  end
@@ -2,7 +2,8 @@
2
2
 
3
3
  require_relative 'test_helper'
4
4
 
5
- class IntegrationTest < MiniTest::Unit::TestCase
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
- item = Item.new 'a'
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.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: 2014-08-18 00:00:00.000000000 Z
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: '1.6'
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: '1.6'
40
+ version: '10.0'
27
41
  - !ruby/object:Gem::Dependency
28
- name: rake
42
+ name: minitest
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - ">="
45
+ - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '0'
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: '0'
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.txt
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: '0'
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.2.2
110
+ rubygems_version: 2.4.5.1
95
111
  signing_key:
96
112
  specification_version: 4
97
113
  summary: Mixin for enumerable maps