curio 0.1.0 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc28163d1bb46f19b67859128f7aa5919dbb3db0
4
- data.tar.gz: 15db1a1eb06af28ab4b140580dadcf3dcf217718
3
+ metadata.gz: 7cd38a97f01363117f4f385112ba501751e369f1
4
+ data.tar.gz: ae94e5f2c0fb34da902b1aabeebe4faaae6bd2c2
5
5
  SHA512:
6
- metadata.gz: 673e78456916956fdb249bebab246af4cea5256d8182ec61bc1427b8dfc887ad13336caf728e7bebcc446518cc899e3267be835767f87db9ff2b7fdcfe079d56
7
- data.tar.gz: 226735b61807e97bfeb135e379b2b42c1012870f42fa37a23f57b42c5d002dabc38eb59293ebf1199da3a0e4b276f063a74c9576a04792a0ec392be3ac15536b
6
+ metadata.gz: f9cf6a715f7497990cd9fd15f0f50804b9f960dfbc6aca8ed01ebd1ec945a2d5d3acf8a7f43d2cfb3366a30de1e090826850b1c940fbce5d79d2a3c0e3eb176d
7
+ data.tar.gz: f0d5db0de2a6163322cbc764e3f83f5bb1e74f19e6080faedcfe7d9c7a0ddf43c69607732915e87516e1f771c987d8985a08ecd79baa65e7abc02f500a44955a
data/.rubocop.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  AllCops:
2
2
  Exclude:
3
+ - Gemfile
3
4
  - bin/**/*
4
5
  - vendor/**/*
5
6
 
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ script: 'bundle exec rake ci'
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - 2.1.2
7
+ - jruby-19mode
8
+ - rbx-2
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
- TODO: Write usage instructions here
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/[my-github-username]/curio/fork )
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
@@ -6,7 +6,7 @@ require 'bundler/gem_tasks'
6
6
  require 'rake/testtask'
7
7
  require 'rubocop/rake_task'
8
8
 
9
- Rubocop::RakeTask.new
9
+ RuboCop::RakeTask.new
10
10
 
11
11
  task default: :test
12
12
  task test: 'test:all'
data/lib/curio.rb CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  require 'curio/version'
4
4
 
5
+ require 'forwardable'
6
+
5
7
  # A mixin to define enumerable maps
6
8
  class Curio < Module
7
9
  # Error raised when fetch cannot find an item with key
data/lib/curio/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  class Curio < Module
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
@@ -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.0
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-05-15 00:00:00.000000000 Z
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