curio 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/.travis.yml +8 -0
- data/README.md +40 -2
- data/Rakefile +1 -1
- data/lib/curio.rb +2 -0
- data/lib/curio/version.rb +1 -1
- data/test/integration_test.rb +11 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7cd38a97f01363117f4f385112ba501751e369f1
|
4
|
+
data.tar.gz: ae94e5f2c0fb34da902b1aabeebe4faaae6bd2c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9cf6a715f7497990cd9fd15f0f50804b9f960dfbc6aca8ed01ebd1ec945a2d5d3acf8a7f43d2cfb3366a30de1e090826850b1c940fbce5d79d2a3c0e3eb176d
|
7
|
+
data.tar.gz: f0d5db0de2a6163322cbc764e3f83f5bb1e74f19e6080faedcfe7d9c7a0ddf43c69607732915e87516e1f771c987d8985a08ecd79baa65e7abc02f500a44955a
|
data/.rubocop.yml
CHANGED
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
A module to ease creation of collections and enumerable maps
|
4
4
|
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/curio.svg)](http://badge.fury.io/rb/curio)
|
6
|
+
[![Build
|
7
|
+
Status](https://travis-ci.org/terlar/curio.svg)](https://travis-ci.org/terlar/curio)
|
8
|
+
[![Code Climate](https://codeclimate.com/github/terlar/curio.png)](https://codeclimate.com/github/terlar/curio)
|
9
|
+
|
5
10
|
## Installation
|
6
11
|
|
7
12
|
Add this line to your application's Gemfile:
|
@@ -18,11 +23,44 @@ Or install it yourself as:
|
|
18
23
|
|
19
24
|
## Usage
|
20
25
|
|
21
|
-
|
26
|
+
```ruby
|
27
|
+
Item = Struct.new :id
|
28
|
+
|
29
|
+
class Collection
|
30
|
+
include Curio.new :id, Integer
|
31
|
+
end
|
32
|
+
|
33
|
+
collection = Collection.new
|
34
|
+
collection << Item.new(1)
|
35
|
+
collection << Item.new(2)
|
36
|
+
|
37
|
+
collection.fetch 1 # => #<struct Item id=1>
|
38
|
+
collection.fetch '1' # => #<struct Item id=1>
|
39
|
+
collection.fetch 3 # => Curio::NotFoundError: Item not found in collection with key: 3
|
40
|
+
collection.fetch 3, :default # => :default
|
41
|
+
collection.fetch 3 do
|
42
|
+
:default
|
43
|
+
end # => :default
|
44
|
+
|
45
|
+
collection[1] # => #<struct Item id=1>
|
46
|
+
collection['1'] # => #<struct Item id=1>
|
47
|
+
collection[3] # => nil
|
48
|
+
|
49
|
+
collection.key? 1 # => true
|
50
|
+
collection.key? '1' # => true
|
51
|
+
collection.key? 3 # => false
|
52
|
+
|
53
|
+
collection.all # => [#<struct Item id=1>, #<struct Item id=2>]
|
54
|
+
collection.last # => #<struct Item id=2>
|
55
|
+
|
56
|
+
collection.each do |item|
|
57
|
+
puts item.id
|
58
|
+
end # => 1 2
|
59
|
+
```
|
22
60
|
|
23
61
|
## Contributing
|
24
62
|
|
25
|
-
1. Fork it ( https://github.com/
|
63
|
+
1. Fork it ( https://github.com/terlar/curio/fork )
|
26
64
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
65
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
66
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/Rakefile
CHANGED
data/lib/curio.rb
CHANGED
data/lib/curio/version.rb
CHANGED
data/test/integration_test.rb
CHANGED
@@ -92,4 +92,15 @@ class IntegrationTest < MiniTest::Unit::TestCase
|
|
92
92
|
'b' => item2
|
93
93
|
}, collection.to_h)
|
94
94
|
end
|
95
|
+
|
96
|
+
def test_coerces_key
|
97
|
+
item = Item.new 1
|
98
|
+
collection << item
|
99
|
+
|
100
|
+
found = collection.fetch '1'
|
101
|
+
assert_equal item, found
|
102
|
+
|
103
|
+
found = collection.fetch :'1'
|
104
|
+
assert_equal item, found
|
105
|
+
end
|
95
106
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.1
|
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-
|
11
|
+
date: 2014-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -61,6 +61,7 @@ extra_rdoc_files: []
|
|
61
61
|
files:
|
62
62
|
- ".gitignore"
|
63
63
|
- ".rubocop.yml"
|
64
|
+
- ".travis.yml"
|
64
65
|
- Gemfile
|
65
66
|
- LICENSE.txt
|
66
67
|
- README.md
|