noeq 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/LICENSE +22 -0
- data/README.md +28 -0
- data/Rakefile +2 -0
- data/lib/noeq.rb +43 -0
- data/noeq.gemspec +16 -0
- metadata +51 -0
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2011 Jonathan Rudenberg
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# noeq-rb
|
2
|
+
|
3
|
+
noeq-rb is a [noeqd](https://github.com/bmizerany/noeqd) GUID client in Ruby.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```
|
8
|
+
gem install noeq
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
### One-time GUID from localhost
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
require 'noeq'
|
17
|
+
Noeq.generate(2) #=> [142692304753262592, 142692304753262593]
|
18
|
+
```
|
19
|
+
|
20
|
+
### Regular usage
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
require 'noeq'
|
24
|
+
|
25
|
+
noeq = Noeq.new('idserver.local')
|
26
|
+
noeq.generate #=> 142692638036852736
|
27
|
+
noeq.generate(5) #=> [142692782450933760, 142692782450933761, 142692782450933762, 142692782450933763, 142692782450933764]
|
28
|
+
```
|
data/Rakefile
ADDED
data/lib/noeq.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'socket'
|
2
|
+
|
3
|
+
class Noeq
|
4
|
+
def self.generate(n=1)
|
5
|
+
noeq = new
|
6
|
+
ids = noeq.generate(n)
|
7
|
+
noeq.disconnect
|
8
|
+
ids
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(server = 'localhost', port = 4444)
|
12
|
+
@server, @port, = server, port
|
13
|
+
connect
|
14
|
+
end
|
15
|
+
|
16
|
+
def connect
|
17
|
+
@socket = TCPSocket.new @server, @port
|
18
|
+
end
|
19
|
+
|
20
|
+
def disconnect
|
21
|
+
@socket.close rescue false
|
22
|
+
end
|
23
|
+
|
24
|
+
def generate(n=1)
|
25
|
+
@socket.send [n].pack('c'), 0
|
26
|
+
ids = (1..n).map { get_id }.compact
|
27
|
+
ids.length > 1 ? ids : ids.first
|
28
|
+
rescue
|
29
|
+
disconnect
|
30
|
+
connect
|
31
|
+
retry
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def get_id
|
37
|
+
(read_long << 32) + read_long
|
38
|
+
end
|
39
|
+
|
40
|
+
def read_long
|
41
|
+
@socket.read(4).unpack("N").first
|
42
|
+
end
|
43
|
+
end
|
data/noeq.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.authors = ["Jonathan Rudenberg"]
|
5
|
+
gem.email = ["jonathan@titanous.com"]
|
6
|
+
gem.description = %q{Ruby noeqd GUID client}
|
7
|
+
gem.summary = %q{Ruby noeqd GUID client}
|
8
|
+
gem.homepage = "http://github.com/titanous/noeq-rb"
|
9
|
+
|
10
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
11
|
+
gem.files = `git ls-files`.split("\n")
|
12
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
13
|
+
gem.name = "noeq"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.version = "0.1.0"
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: noeq
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jonathan Rudenberg
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-12-02 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Ruby noeqd GUID client
|
15
|
+
email:
|
16
|
+
- jonathan@titanous.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- LICENSE
|
23
|
+
- README.md
|
24
|
+
- Rakefile
|
25
|
+
- lib/noeq.rb
|
26
|
+
- noeq.gemspec
|
27
|
+
homepage: http://github.com/titanous/noeq-rb
|
28
|
+
licenses: []
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements: []
|
46
|
+
rubyforge_project:
|
47
|
+
rubygems_version: 1.8.11
|
48
|
+
signing_key:
|
49
|
+
specification_version: 3
|
50
|
+
summary: Ruby noeqd GUID client
|
51
|
+
test_files: []
|