iuid 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +4 -0
- data/.rspec +1 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +39 -0
- data/LICENSE.txt +15 -0
- data/README.md +74 -0
- data/Rakefile +53 -0
- data/bin/iuid +76 -0
- data/iuid.gemspec +75 -0
- data/lib/VERSION +4 -0
- data/lib/iuid.rb +93 -0
- data/lib/iuid/default_config.yaml +6 -0
- data/lib/iuid/version.rb +22 -0
- data/spec/data/.keep +0 -0
- data/spec/iuid_spec.rb +72 -0
- data/spec/spec_helper.rb +36 -0
- metadata +189 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem "moneta", ">= 0.6.1", :git => 'git://github.com/duritong/moneta.git'
|
7
|
+
|
8
|
+
# Add dependencies to develop your gem here.
|
9
|
+
# Include everything needed to run rake, tests, features, etc.
|
10
|
+
group :development do
|
11
|
+
gem "rspec", "~> 2.3.0"
|
12
|
+
gem "rdoc", "~> 3.8"
|
13
|
+
gem "mocha"
|
14
|
+
gem "bundler", "~> 1.0.0"
|
15
|
+
gem "jeweler", "~> 1.6.4"
|
16
|
+
gem "rcov", ">= 0"
|
17
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git://github.com/duritong/moneta.git
|
3
|
+
revision: 38125d0d598891f27fa6836cbc57cb928831ac4f
|
4
|
+
specs:
|
5
|
+
moneta (0.6.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.1.2)
|
11
|
+
git (1.2.5)
|
12
|
+
jeweler (1.6.4)
|
13
|
+
bundler (~> 1.0)
|
14
|
+
git (>= 1.2.5)
|
15
|
+
rake
|
16
|
+
mocha (0.9.12)
|
17
|
+
rake (0.9.2)
|
18
|
+
rcov (0.9.9)
|
19
|
+
rdoc (3.8)
|
20
|
+
rspec (2.3.0)
|
21
|
+
rspec-core (~> 2.3.0)
|
22
|
+
rspec-expectations (~> 2.3.0)
|
23
|
+
rspec-mocks (~> 2.3.0)
|
24
|
+
rspec-core (2.3.1)
|
25
|
+
rspec-expectations (2.3.0)
|
26
|
+
diff-lcs (~> 1.1.2)
|
27
|
+
rspec-mocks (2.3.0)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
ruby
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
bundler (~> 1.0.0)
|
34
|
+
jeweler (~> 1.6.4)
|
35
|
+
mocha
|
36
|
+
moneta (>= 0.6.1)!
|
37
|
+
rcov
|
38
|
+
rdoc (~> 3.8)
|
39
|
+
rspec (~> 2.3.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Trocla - a simple password generator and storage
|
2
|
+
Copyright (C) 2011 Marcel Haerry
|
3
|
+
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
5
|
+
it under the terms of the GNU General Public License as published by
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
7
|
+
any later version.
|
8
|
+
|
9
|
+
This program is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
GNU General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU General Public License
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
data/README.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# iuid
|
2
|
+
|
3
|
+
iuid is a simple username / uid storage that can autogenerate uids.
|
4
|
+
|
5
|
+
iuid will either retrieve an existing uid for a category/key or generate the next available
|
6
|
+
uid. If this uid collides with a range of the next category an exception is raised.
|
7
|
+
For each category a starting uid is configured, which will then also set the max uid by the
|
8
|
+
next category. The global max uid is 4294967295 but can be configured via the configuration
|
9
|
+
option `max_uid`.
|
10
|
+
|
11
|
+
You can use any kind of key/value based storage supported by moneta for
|
12
|
+
iuid. By default it uses a simple yaml file.
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
### create
|
17
|
+
|
18
|
+
Assuming that we have an empty iuid storage.
|
19
|
+
|
20
|
+
trocla create user1 category1
|
21
|
+
|
22
|
+
This will create (if not already stored in iuid) a random uid for the key
|
23
|
+
user1 and use category1 as a range information from which within a uid should
|
24
|
+
should be created.
|
25
|
+
|
26
|
+
If the uid already exists it will simply return the matching uid.
|
27
|
+
|
28
|
+
### get
|
29
|
+
|
30
|
+
Get simply returns a stored uid. It will not create a new uid.
|
31
|
+
|
32
|
+
Assuming that we are still working with the same storage
|
33
|
+
|
34
|
+
iuid get user1
|
35
|
+
|
36
|
+
will return the generated uid, while
|
37
|
+
|
38
|
+
iuid get user3
|
39
|
+
|
40
|
+
This will return nothing, as no uid has been generated so far for that user.
|
41
|
+
|
42
|
+
### set
|
43
|
+
|
44
|
+
iuid set user3 1024
|
45
|
+
|
46
|
+
This will set the uid 1024 for the key user3
|
47
|
+
|
48
|
+
### delete
|
49
|
+
|
50
|
+
iuid delete user1 plain
|
51
|
+
|
52
|
+
This will delete the stored uid and return it.
|
53
|
+
|
54
|
+
## Installation
|
55
|
+
|
56
|
+
Simply build and install the gem. BUT trocla is based on a not yet published
|
57
|
+
version of [moneta](https://github.com/wycats/moneta). You can build a new
|
58
|
+
moneta version based on the latest master as version 0.6.1 and instal that one.
|
59
|
+
|
60
|
+
## Contributing to iuid
|
61
|
+
|
62
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
63
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
64
|
+
* Fork the project
|
65
|
+
* Start a feature/bugfix branch
|
66
|
+
* Commit and push until you are happy with your contribution
|
67
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
68
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
69
|
+
|
70
|
+
## Copyright
|
71
|
+
|
72
|
+
Copyright (c) 2011 mh. See LICENSE.txt for
|
73
|
+
further details.
|
74
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
|
15
|
+
require 'jeweler'
|
16
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
17
|
+
require 'iuid'
|
18
|
+
Jeweler::Tasks.new do |gem|
|
19
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
20
|
+
gem.name = "iuid"
|
21
|
+
gem.homepage = "http://www.immerda.ch"
|
22
|
+
gem.license = "GPLv3"
|
23
|
+
gem.summary = "Iuid a simple uid generator and storage"
|
24
|
+
gem.description = "Iuid generates and keeps uids stored. It generates the next unique uid based on a category range"
|
25
|
+
gem.email = "mh+iuid@immerda.ch"
|
26
|
+
gem.authors = ["mh"]
|
27
|
+
gem.version = Iuid::VERSION::STRING
|
28
|
+
# dependencies defined in Gemfile
|
29
|
+
end
|
30
|
+
Jeweler::RubygemsDotOrgTasks.new
|
31
|
+
|
32
|
+
require 'rspec/core'
|
33
|
+
require 'rspec/core/rake_task'
|
34
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
35
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
36
|
+
end
|
37
|
+
|
38
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
39
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
40
|
+
spec.rcov = true
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :spec
|
44
|
+
|
45
|
+
gem 'rdoc'
|
46
|
+
require 'rdoc/task'
|
47
|
+
RDoc::Task.new do |rdoc|
|
48
|
+
version = Iuid::VERSION::STRING
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "iuid #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/bin/iuid
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# CLI client for Trocla.
|
3
|
+
#
|
4
|
+
require 'rubygems'
|
5
|
+
require 'iuid'
|
6
|
+
require 'optparse'
|
7
|
+
require 'yaml'
|
8
|
+
|
9
|
+
options = { :config_file => nil }
|
10
|
+
|
11
|
+
OptionParser.new do |opts|
|
12
|
+
opts.on("--version", "-V", "Version information") do
|
13
|
+
puts Trocla::VERSION::STRING
|
14
|
+
exit
|
15
|
+
end
|
16
|
+
|
17
|
+
opts.on("--config CONFIG", "-c", "Configuration file") do |v|
|
18
|
+
if File.exist?(v)
|
19
|
+
options[:config_file] = v
|
20
|
+
else
|
21
|
+
STDERR.puts "Cannot find config file: #{v}"
|
22
|
+
exit 1
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end.parse!
|
26
|
+
|
27
|
+
def create(options)
|
28
|
+
miss('category') unless options[:category]
|
29
|
+
Iuid.new(options.delete(:config_file)).create(
|
30
|
+
options.delete(:name),
|
31
|
+
options.delete(:category)
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
def get(options)
|
36
|
+
Iuid.new(options.delete(:config_file)).get(
|
37
|
+
options.delete(:name)
|
38
|
+
)
|
39
|
+
end
|
40
|
+
def set(options)
|
41
|
+
miss('uid') unless options[:category] # this is actually the uid
|
42
|
+
Iuid.new(options.delete(:config_file)).set(
|
43
|
+
options.delete(:name),
|
44
|
+
options.delete(:category)
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
def delete(options)
|
49
|
+
Iuid.new(options.delete(:config_file)).delete(
|
50
|
+
options.delete(:name)
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
def miss(what)
|
55
|
+
STDERR.puts "Missing #{what}, exiting..."
|
56
|
+
exit 1
|
57
|
+
end
|
58
|
+
|
59
|
+
actions=['create','get','set','delete']
|
60
|
+
|
61
|
+
if !(ARGV.length < 2) && (action=ARGV.shift) && actions.include?(action)
|
62
|
+
options[:name] = ARGV.shift
|
63
|
+
options[:category] = ARGV.shift
|
64
|
+
begin
|
65
|
+
if result = send(action,options)
|
66
|
+
puts result.is_a?(String) ? result : result.inspect
|
67
|
+
end
|
68
|
+
rescue Exception => e
|
69
|
+
STDERR.puts "Action failed with the following message: #{e.message}" unless e.message == 'exit'
|
70
|
+
exit 1
|
71
|
+
end
|
72
|
+
else
|
73
|
+
STDERR.puts "Please supply one of the following actions: #{actions.join(', ')}"
|
74
|
+
exit 1
|
75
|
+
end
|
76
|
+
|
data/iuid.gemspec
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{iuid}
|
8
|
+
s.version = "0.0.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["mh"]
|
12
|
+
s.date = %q{2012-01-05}
|
13
|
+
s.default_executable = %q{iuid}
|
14
|
+
s.description = %q{Iuid generates and keeps uids stored. It generates the next unique uid based on a category range}
|
15
|
+
s.email = %q{mh+iuid@immerda.ch}
|
16
|
+
s.executables = ["iuid"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE.txt",
|
19
|
+
"README.md"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".rspec",
|
24
|
+
"Gemfile",
|
25
|
+
"Gemfile.lock",
|
26
|
+
"LICENSE.txt",
|
27
|
+
"README.md",
|
28
|
+
"Rakefile",
|
29
|
+
"bin/iuid",
|
30
|
+
"iuid.gemspec",
|
31
|
+
"lib/VERSION",
|
32
|
+
"lib/iuid.rb",
|
33
|
+
"lib/iuid/default_config.yaml",
|
34
|
+
"lib/iuid/version.rb",
|
35
|
+
"spec/data/.keep",
|
36
|
+
"spec/iuid_spec.rb",
|
37
|
+
"spec/spec_helper.rb"
|
38
|
+
]
|
39
|
+
s.homepage = %q{http://www.immerda.ch}
|
40
|
+
s.licenses = ["GPLv3"]
|
41
|
+
s.require_paths = ["lib"]
|
42
|
+
s.rubygems_version = %q{1.6.2}
|
43
|
+
s.summary = %q{Iuid a simple uid generator and storage}
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
s.specification_version = 3
|
47
|
+
|
48
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
|
+
s.add_runtime_dependency(%q<moneta>, [">= 0.6.1"])
|
50
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
51
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.8"])
|
52
|
+
s.add_development_dependency(%q<mocha>, [">= 0"])
|
53
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
54
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
55
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<moneta>, [">= 0.6.1"])
|
58
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
59
|
+
s.add_dependency(%q<rdoc>, ["~> 3.8"])
|
60
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
61
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
62
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
63
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
64
|
+
end
|
65
|
+
else
|
66
|
+
s.add_dependency(%q<moneta>, [">= 0.6.1"])
|
67
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
68
|
+
s.add_dependency(%q<rdoc>, ["~> 3.8"])
|
69
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
70
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
71
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
72
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
data/lib/VERSION
ADDED
data/lib/iuid.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'iuid/version'
|
2
|
+
|
3
|
+
class Iuid
|
4
|
+
|
5
|
+
def initialize(config_file=nil)
|
6
|
+
if config_file
|
7
|
+
@config_file = File.expand_path(config_file)
|
8
|
+
elsif File.exists?(def_config_file=File.expand_path('~/.iuid.yaml')) || File.exists?(def_config_file=File.expand_path('/etc/iuid.yaml'))
|
9
|
+
@config_file = def_config_file
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def create(name,category)
|
14
|
+
unless (uid=get(name)).nil?
|
15
|
+
return uid
|
16
|
+
end
|
17
|
+
|
18
|
+
set(name,next_uid(category))
|
19
|
+
end
|
20
|
+
|
21
|
+
def get(name)
|
22
|
+
cache.fetch(name)
|
23
|
+
end
|
24
|
+
|
25
|
+
def delete(name)
|
26
|
+
cache.delete(name)
|
27
|
+
end
|
28
|
+
|
29
|
+
def set(name,uid)
|
30
|
+
cache[name] = uid
|
31
|
+
cache['_all_uids'] = (alluids | [ uid ])
|
32
|
+
uid
|
33
|
+
end
|
34
|
+
|
35
|
+
protected
|
36
|
+
|
37
|
+
def next_uid(category)
|
38
|
+
raise "Category #{category} is not configured!" unless max_uid=categories[category]
|
39
|
+
if (curr_uid = cache["_category_#{category}_curr_uid"]) || max_uid && alluids.include?(curr_uid=max_uid)
|
40
|
+
uid=curr_uid + 1
|
41
|
+
while alluids.include?(uid)
|
42
|
+
uid = curr_uid + 1
|
43
|
+
end
|
44
|
+
raise "Max uid is 4294967295" if uid > 4294967295
|
45
|
+
if coll_category = categories.keys.find{|c| categories[c] > max_uid && uid >= categories[c] }
|
46
|
+
raise "Next available uid (uid) collides with category #{coll_category}"
|
47
|
+
end
|
48
|
+
else
|
49
|
+
uid = max_uid
|
50
|
+
end
|
51
|
+
cache["_category_#{category}_curr_uid"] = uid
|
52
|
+
uid
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
def cache
|
57
|
+
@cache ||= build_cache
|
58
|
+
end
|
59
|
+
|
60
|
+
def alluids
|
61
|
+
cache.fetch('_all_uids',[])
|
62
|
+
end
|
63
|
+
|
64
|
+
def categories
|
65
|
+
config['categories'] || {}
|
66
|
+
end
|
67
|
+
|
68
|
+
def build_cache
|
69
|
+
require 'moneta'
|
70
|
+
require "moneta/adapters/#{config['adapter'].downcase}"
|
71
|
+
lconfig = config
|
72
|
+
Moneta::Builder.new { run eval( "Moneta::Adapters::#{lconfig['adapter']}"), lconfig['adapter_options'] }
|
73
|
+
end
|
74
|
+
|
75
|
+
def config
|
76
|
+
@config ||= read_config
|
77
|
+
end
|
78
|
+
|
79
|
+
def read_config
|
80
|
+
if @config_file.nil?
|
81
|
+
default_config
|
82
|
+
else
|
83
|
+
raise "Configfile #{@config_file} does not exist!" unless File.exists?(@config_file)
|
84
|
+
default_config.merge(YAML.load(File.read(@config_file)))
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def default_config
|
89
|
+
require 'yaml'
|
90
|
+
YAML.load(File.read(File.expand_path(File.join(File.dirname(__FILE__),'iuid','default_config.yaml'))))
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
data/lib/iuid/version.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
class Iuid
|
3
|
+
class VERSION
|
4
|
+
version = {}
|
5
|
+
File.read(File.join(File.dirname(__FILE__), '../', 'VERSION')).each_line do |line|
|
6
|
+
type, value = line.chomp.split(":")
|
7
|
+
next if type =~ /^\s+$/ || value =~ /^\s+$/
|
8
|
+
version[type] = value
|
9
|
+
end
|
10
|
+
|
11
|
+
MAJOR = version['major']
|
12
|
+
MINOR = version['minor']
|
13
|
+
PATCH = version['patch']
|
14
|
+
BUILD = version['build']
|
15
|
+
|
16
|
+
STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
|
17
|
+
|
18
|
+
def self.version
|
19
|
+
STRING
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/spec/data/.keep
ADDED
File without changes
|
data/spec/iuid_spec.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Iuid" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
Iuid.any_instance.expects(:read_config).returns(test_config)
|
7
|
+
@iuid = Iuid.new
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "get" do
|
11
|
+
it "should return nil as default" do
|
12
|
+
@iuid.get('get_test').should be_nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "create" do
|
17
|
+
it "should create a new uid if not yet present" do
|
18
|
+
@iuid.get('create_test').should be_nil
|
19
|
+
@iuid.create('create_test','global').should eql(100)
|
20
|
+
@iuid.get('create_test').should eql(100)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should increase the next uid by one" do
|
24
|
+
@iuid.get('create_test2').should be_nil
|
25
|
+
|
26
|
+
@iuid.create('create_test2','global').should eql(100)
|
27
|
+
@iuid.get('create_test2').should eql(100)
|
28
|
+
|
29
|
+
@iuid.create('create_test3','global').should eql(101)
|
30
|
+
@iuid.get('create_test3').should eql(101)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should raise an exception if the next category is reached" do
|
34
|
+
@iuid.create('create_test4','global2').should eql(200)
|
35
|
+
lambda { @iuid.create('create_test5','global2') }.should raise_error(Exception)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should not create an existing uid" do
|
39
|
+
@iuid.set('double_test1',100).should eql(100)
|
40
|
+
@iuid.create('double_test2','global').should eql(101)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should not create an uid > 4294967295" do
|
44
|
+
@iuid.create('max_test1','max').should eql(4294967295)
|
45
|
+
lambda { @iuid.create('max_test2','max') }.should raise_error(Exception)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "set" do
|
50
|
+
it "should set an uid and return it" do
|
51
|
+
@iuid.get('set_test1').should be_nil
|
52
|
+
@iuid.set('set_test1',100).should eql(100)
|
53
|
+
@iuid.get('set_test1').should_not be_nil
|
54
|
+
@iuid.get('set_test1').should be(100)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "delete" do
|
59
|
+
it "should delete a given uid" do
|
60
|
+
@iuid.create('delete_test1','global').should_not be_nil
|
61
|
+
@iuid.get('delete_test1').should_not be_nil
|
62
|
+
@iuid.delete('delete_test1').should_not be_nil
|
63
|
+
@iuid.get('delete_test1').should be_nil
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "VERSION" do
|
68
|
+
it "should return a version" do
|
69
|
+
Iuid::VERSION::STRING.should_not be_empty
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'mocha'
|
5
|
+
require 'iuid'
|
6
|
+
|
7
|
+
# Requires supporting files with custom matchers and macros, etc,
|
8
|
+
# in ./support/ and its subdirectories.
|
9
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
def default_config
|
16
|
+
@default_config ||= YAML.load(File.read(File.expand_path(base_dir+'/lib/iuid/default_config.yaml')))
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_config
|
20
|
+
return @config unless @config.nil?
|
21
|
+
@config = default_config
|
22
|
+
yaml_path = File.expand_path(base_dir+'/spec/data/test_config.yaml')
|
23
|
+
File.unlink(yaml_path) if File.exists?(yaml_path)
|
24
|
+
@config['categories'] = {
|
25
|
+
'global' => 100,
|
26
|
+
'global2' => 200,
|
27
|
+
'global3' => 201,
|
28
|
+
'max' => 4294967295
|
29
|
+
}
|
30
|
+
@config['adapter_options'][:path] = yaml_path
|
31
|
+
@config
|
32
|
+
end
|
33
|
+
|
34
|
+
def base_dir
|
35
|
+
File.dirname(__FILE__)+'/../'
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,189 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: iuid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- mh
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-01-05 00:00:00 +01:00
|
19
|
+
default_executable: iuid
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
type: :runtime
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 5
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
- 6
|
32
|
+
- 1
|
33
|
+
version: 0.6.1
|
34
|
+
version_requirements: *id001
|
35
|
+
name: moneta
|
36
|
+
prerelease: false
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
type: :development
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 2
|
47
|
+
- 3
|
48
|
+
- 0
|
49
|
+
version: 2.3.0
|
50
|
+
version_requirements: *id002
|
51
|
+
name: rspec
|
52
|
+
prerelease: false
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
type: :development
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ~>
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 23
|
61
|
+
segments:
|
62
|
+
- 3
|
63
|
+
- 8
|
64
|
+
version: "3.8"
|
65
|
+
version_requirements: *id003
|
66
|
+
name: rdoc
|
67
|
+
prerelease: false
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
type: :development
|
70
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 3
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
version: "0"
|
79
|
+
version_requirements: *id004
|
80
|
+
name: mocha
|
81
|
+
prerelease: false
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
type: :development
|
84
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
hash: 23
|
90
|
+
segments:
|
91
|
+
- 1
|
92
|
+
- 0
|
93
|
+
- 0
|
94
|
+
version: 1.0.0
|
95
|
+
version_requirements: *id005
|
96
|
+
name: bundler
|
97
|
+
prerelease: false
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
type: :development
|
100
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ~>
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
hash: 7
|
106
|
+
segments:
|
107
|
+
- 1
|
108
|
+
- 6
|
109
|
+
- 4
|
110
|
+
version: 1.6.4
|
111
|
+
version_requirements: *id006
|
112
|
+
name: jeweler
|
113
|
+
prerelease: false
|
114
|
+
- !ruby/object:Gem::Dependency
|
115
|
+
type: :development
|
116
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
hash: 3
|
122
|
+
segments:
|
123
|
+
- 0
|
124
|
+
version: "0"
|
125
|
+
version_requirements: *id007
|
126
|
+
name: rcov
|
127
|
+
prerelease: false
|
128
|
+
description: Iuid generates and keeps uids stored. It generates the next unique uid based on a category range
|
129
|
+
email: mh+iuid@immerda.ch
|
130
|
+
executables:
|
131
|
+
- iuid
|
132
|
+
extensions: []
|
133
|
+
|
134
|
+
extra_rdoc_files:
|
135
|
+
- LICENSE.txt
|
136
|
+
- README.md
|
137
|
+
files:
|
138
|
+
- .document
|
139
|
+
- .rspec
|
140
|
+
- Gemfile
|
141
|
+
- Gemfile.lock
|
142
|
+
- LICENSE.txt
|
143
|
+
- README.md
|
144
|
+
- Rakefile
|
145
|
+
- bin/iuid
|
146
|
+
- iuid.gemspec
|
147
|
+
- lib/VERSION
|
148
|
+
- lib/iuid.rb
|
149
|
+
- lib/iuid/default_config.yaml
|
150
|
+
- lib/iuid/version.rb
|
151
|
+
- spec/data/.keep
|
152
|
+
- spec/iuid_spec.rb
|
153
|
+
- spec/spec_helper.rb
|
154
|
+
has_rdoc: true
|
155
|
+
homepage: http://www.immerda.ch
|
156
|
+
licenses:
|
157
|
+
- GPLv3
|
158
|
+
post_install_message:
|
159
|
+
rdoc_options: []
|
160
|
+
|
161
|
+
require_paths:
|
162
|
+
- lib
|
163
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
164
|
+
none: false
|
165
|
+
requirements:
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
hash: 3
|
169
|
+
segments:
|
170
|
+
- 0
|
171
|
+
version: "0"
|
172
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
173
|
+
none: false
|
174
|
+
requirements:
|
175
|
+
- - ">="
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
hash: 3
|
178
|
+
segments:
|
179
|
+
- 0
|
180
|
+
version: "0"
|
181
|
+
requirements: []
|
182
|
+
|
183
|
+
rubyforge_project:
|
184
|
+
rubygems_version: 1.6.2
|
185
|
+
signing_key:
|
186
|
+
specification_version: 3
|
187
|
+
summary: Iuid a simple uid generator and storage
|
188
|
+
test_files: []
|
189
|
+
|