unique 0.0.1 → 0.1.0
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.
- data/CHANGELOG.md +4 -0
- data/README.md +25 -1
- data/lib/unique.rb +4 -0
- data/lib/unique/version.rb +1 -1
- metadata +27 -7
- checksums.yaml +0 -15
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
[](https://travis-ci.org/b264/unique)
|
1
2
|
# unique
|
2
3
|
|
3
|
-
A lightweight Ruby gem that prevents a block from returning the same object twice.
|
4
|
+
A lightweight Ruby gem with zero dependencies that prevents a block from returning the same object twice.
|
4
5
|
|
5
6
|
## Setup
|
6
7
|
|
@@ -50,6 +51,29 @@ The maximum number of times the block will be yielded looking for a unique objec
|
|
50
51
|
Unique.max_tries= 10
|
51
52
|
```
|
52
53
|
|
54
|
+
## Cleanup
|
55
|
+
|
56
|
+
`Unique.reset!` will clear previous objects and allow them to be used. This is
|
57
|
+
useful in your test suites `before` blocks.
|
58
|
+
|
59
|
+
### Example
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
1.9.3-p551 :001 > Unique.next!{ rand(1) }
|
63
|
+
=> 0
|
64
|
+
1.9.3-p551 :002 > Unique.next!{ rand(1) }
|
65
|
+
Unique::NoUniqueObjects: An unused, unique object could not be found in 4096 tries (["(irb)", 2])
|
66
|
+
from /home/devbox/code/unique/lib/unique.rb:22:in `block in next!'
|
67
|
+
from /home/devbox/code/unique/lib/unique.rb:20:in `loop'
|
68
|
+
from /home/devbox/code/unique/lib/unique.rb:20:in `next!'
|
69
|
+
from (irb):6
|
70
|
+
from /home/devbox/.rvm/rubies/ruby-1.9.3-p551/bin/irb:12:in `<main>'
|
71
|
+
1.9.3-p551 :003 > Unique.reset!
|
72
|
+
=> []
|
73
|
+
1.9.3-p551 :004 > Unique.next!{ rand(1) }
|
74
|
+
=> 0
|
75
|
+
```
|
76
|
+
|
53
77
|
## Is it any good?
|
54
78
|
|
55
79
|
[Yes](https://news.ycombinator.com/item?id=3067434)
|
data/lib/unique.rb
CHANGED
data/lib/unique/version.rb
CHANGED
metadata
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unique
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Brian Giaraffa
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2016-
|
12
|
+
date: 2016-10-04 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: rake
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
19
|
- - ~>
|
18
20
|
- !ruby/object:Gem::Version
|
@@ -20,10 +22,27 @@ dependencies:
|
|
20
22
|
type: :development
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
27
|
- - ~>
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: 11.2.2
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '3.2'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.2'
|
27
46
|
description: Prevents a block from returning the same object twice.
|
28
47
|
email:
|
29
48
|
- public88878878887@hotmail.com
|
@@ -31,33 +50,34 @@ executables: []
|
|
31
50
|
extensions: []
|
32
51
|
extra_rdoc_files: []
|
33
52
|
files:
|
53
|
+
- lib/unique.rb
|
54
|
+
- lib/unique/version.rb
|
34
55
|
- CHANGELOG.md
|
35
56
|
- LICENSE.txt
|
36
57
|
- README.md
|
37
|
-
- lib/unique.rb
|
38
|
-
- lib/unique/version.rb
|
39
58
|
homepage: https://github.com/b264/unique
|
40
59
|
licenses:
|
41
60
|
- ISC
|
42
|
-
metadata: {}
|
43
61
|
post_install_message:
|
44
62
|
rdoc_options: []
|
45
63
|
require_paths:
|
46
64
|
- lib
|
47
65
|
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
48
67
|
requirements:
|
49
68
|
- - ! '>='
|
50
69
|
- !ruby/object:Gem::Version
|
51
70
|
version: 1.9.3
|
52
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
53
73
|
requirements:
|
54
74
|
- - ! '>='
|
55
75
|
- !ruby/object:Gem::Version
|
56
76
|
version: '0'
|
57
77
|
requirements: []
|
58
78
|
rubyforge_project:
|
59
|
-
rubygems_version:
|
79
|
+
rubygems_version: 1.8.23.2
|
60
80
|
signing_key:
|
61
|
-
specification_version:
|
81
|
+
specification_version: 3
|
62
82
|
summary: Prevent duplicates
|
63
83
|
test_files: []
|
checksums.yaml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
---
|
2
|
-
!binary "U0hBMQ==":
|
3
|
-
metadata.gz: !binary |-
|
4
|
-
OTg3ODg5YjliNDY5YzJjZTQ4OGI1ODA0NmI1NWIzYjM3MmEwMjZiYw==
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
ZDE0MmI0YTAzYTljYWY1NTMyY2I5OTk5MmI3YWQ5NTZjOWVjN2MyMA==
|
7
|
-
SHA512:
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
MTc3ODM0NzY4ZTRmYWVlMzA0MThiMzUxZmFlMzMyZGZlZTliOGJlYjA2ZjVk
|
10
|
-
N2ZmM2Q2NWM3ODBkNjVjMzc3NDczMGZiMDhmYjM1NjAwNjE3Mjc5MWZlYTMw
|
11
|
-
ZTI4NWE3M2IzYjI3YTA3YTA5ZGViMjZhNjM1MDljMjhhMDhkZDU=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NWMzN2I4NWMwZmViODI4MWViNTdkMTE0MTA3MjhiYTEwMTE1OTE2MTcwZmEy
|
14
|
-
NWUzNmY4N2VhNDJiN2RlOTYxZDc3ZmZkMzFmMzVlZDFiMmYxMDM2YTE5Y2Zm
|
15
|
-
ODkyNjU2MTAwNzlhNDAwYzIwMzgyYWZiMWEwZjY4ZTJhNjFmYWM=
|