noid 0.5.5 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 030be3b01cc2ea47116b13957cfbd64b01097af0
4
+ data.tar.gz: 21bd9b4385520538ab7d5072623b654211d5c118
5
+ SHA512:
6
+ metadata.gz: 7d011eb2d80e3ce506a5993d4a1fde57676bafa06a6e34d4332b49fb9b2c85d7f6f0284ef3d00c130aa6f69bf547fdbf82346103c2b3b26a71ddddb0fee6bd81
7
+ data.tar.gz: 22166b166b3b30d76bd016325e967afc76246115ddb04fea740688a94783aabca64176d029dcc69526da66b67f9b0746617841d848af6525dc64e1fa0773a5de
checksums.yaml.gz.sig ADDED
Binary file
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.3
5
+ - jruby-18mode
6
+ script: bundle exec rake
data/Gemfile CHANGED
@@ -1,4 +1,9 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in noid.gemspec
3
+ # Specify your gem's dependencies in test.gemspec
4
4
  gemspec
5
+
6
+
7
+ gem 'rcov', :platform => :mri_18
8
+ gem 'simplecov', :platform => :mri_19
9
+ gem 'simplecov-rcov', :platform => :mri_19
@@ -1,8 +1,8 @@
1
- = noid
1
+ # noid
2
2
 
3
3
  Ruby implementation of NOID (Nice Opaque Identifier)
4
4
 
5
- == Contributing to noid
5
+ ## Contributing to noid
6
6
 
7
7
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
8
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
@@ -12,7 +12,7 @@ Ruby implementation of NOID (Nice Opaque Identifier)
12
12
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
13
  * 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.
14
14
 
15
- == Copyright
15
+ ## Copyright
16
16
 
17
17
  Copyright (c) 2010 Chris Beer. See LICENSE.txt for
18
18
  further details.
data/Rakefile CHANGED
@@ -1,8 +1,45 @@
1
- require 'bundler/gem_tasks'
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+
11
+ Bundler::GemHelper.install_tasks
2
12
 
13
+ require 'rake'
14
+ require 'rspec'
3
15
  require 'rspec/core/rake_task'
4
16
 
17
+ desc 'Default: run specs.'
18
+ task :default => :spec
19
+
5
20
  RSpec::Core::RakeTask.new do |t|
6
- t.rspec_opts = ["-c", "-f progress", "-r ./spec/spec_helper.rb"]
7
- t.pattern = 'spec/**/*_spec.rb'
21
+ if ENV['COVERAGE'] and RUBY_VERSION =~ /^1.8/
22
+ t.rcov = true
23
+ t.rcov_opts = ['--exclude', 'spec', '--exclude', 'gems']
24
+ end
8
25
  end
26
+
27
+ # Use yard to build docs
28
+ begin
29
+ require 'yard'
30
+ require 'yard/rake/yardoc_task'
31
+ project_root = File.expand_path(File.dirname(__FILE__))
32
+ doc_destination = File.join(project_root, 'doc')
33
+
34
+ YARD::Rake::YardocTask.new(:doc) do |yt|
35
+ yt.files = Dir.glob(File.join(project_root, 'lib', '**', '*.rb')) +
36
+ [ File.join(project_root, 'README.md') ]
37
+ yt.options = ['--output-dir', doc_destination, '--readme', 'README.md']
38
+ end
39
+ rescue LoadError
40
+ desc "Generate YARD Documentation"
41
+ task :doc do
42
+ abort "Please install the YARD gem to generate rdoc."
43
+ end
44
+ end
45
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.5
1
+ 0.6.5
data/lib/noid/minter.rb CHANGED
@@ -5,13 +5,21 @@ module Noid
5
5
  attr_reader :seed, :seq
6
6
  attr_writer :counters
7
7
 
8
- def initialize args = {}
9
- seed(args[:seed], args[:seq])
10
- @template_string = args[:template]
11
- @max_counters = args[:max_counters]
12
- @counters = args[:counters]
13
-
14
- @after_mint = args[:after_mint]
8
+ def initialize options = {}
9
+
10
+ if options[:state]
11
+ seed(options[:seed])
12
+ @seq = options[:seq]
13
+ @template_string = options[:template]
14
+ @counters = options[:counters]
15
+ else
16
+ seed(options[:seed], options[:seq])
17
+ @template_string = options[:template]
18
+ @max_counters = options[:max_counters]
19
+ @counters = options[:counters]
20
+
21
+ @after_mint = options[:after_mint]
22
+ end
15
23
  end
16
24
 
17
25
  ##
@@ -75,7 +83,7 @@ module Noid
75
83
  @seq += 1
76
84
  case template.generator
77
85
  when 'r'
78
- raise Exception if counters.size == 0
86
+ raise Exception("Exhausted noid sequence pool") if counters.size == 0
79
87
  i = @rand.rand(counters.size)
80
88
  n = counters[i][:value]
81
89
  counters[i][:value] += 1
@@ -108,7 +116,7 @@ module Noid
108
116
  end
109
117
 
110
118
  def dump
111
- { :seq => @seq, :seed => @seed, :template => template.template, :counters => Marshal.load(Marshal.dump(counters)) }
119
+ { :state => true, :seq => @seq, :seed => @seed, :template => template.template, :counters => Marshal.load(Marshal.dump(counters)) }
112
120
  end
113
121
  end
114
122
  end
data/noid.gemspec CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  s.add_dependency "backports"
22
- s.add_development_dependency "bundler", "~> 1.1.0"
22
+ s.add_development_dependency "bundler"
23
+ s.add_development_dependency "rake"
23
24
  s.add_development_dependency "rspec", ">= 2.0"
24
25
  end
@@ -1,3 +1,5 @@
1
+ require 'spec_helper'
2
+
1
3
  describe Noid::Minter do
2
4
  it "should mint a few random 3-digit numbers" do
3
5
  minter = Noid::Minter.new(:template => '.rddd')
@@ -128,7 +130,7 @@ describe Noid::Minter do
128
130
  end
129
131
  end
130
132
 
131
- describe "dump" do
133
+ describe "dump and reload" do
132
134
  it "should dump the minter state" do
133
135
  minter = Noid::Minter.new(:template => ".sddd")
134
136
  d = minter.dump
@@ -163,4 +165,35 @@ describe Noid::Minter do
163
165
 
164
166
  end
165
167
 
168
+ describe "multithreading-safe example" do
169
+ before do
170
+ require 'yaml'
171
+ minter = Noid::Minter.new(:template => '.rd')
172
+ yaml = YAML::dump(minter.dump)
173
+ File.open('minter-state', 'w') { |f| f.write yaml }
174
+ end
175
+
176
+ after do
177
+ File.delete('minter-state')
178
+ end
179
+
180
+ it "should persist state to the filesystem" do
181
+
182
+ File.open("minter-state", File::RDWR|File::CREAT, 0644) {|f|
183
+ f.flock(File::LOCK_EX)
184
+ yaml = YAML::load(f.read)
185
+
186
+ minter = Noid::Minter.new(yaml)
187
+
188
+ f.rewind
189
+ yaml = YAML::dump(minter.dump)
190
+ f.write yaml
191
+ f.flush
192
+ f.truncate(f.pos)
193
+ }
194
+
195
+ end
196
+ end
197
+
198
+
166
199
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,12 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
+
4
+ if ENV['COVERAGE'] and RUBY_VERSION =~ /^1.9/
5
+ require 'simplecov'
6
+
7
+ SimpleCov.start
8
+ end
9
+
3
10
  require 'noid'
4
11
 
5
12
  RSpec.configure do |config|
data.tar.gz.sig ADDED
@@ -0,0 +1 @@
1
+ ��ªS�Fn⇉۠rhq�jA�< �̗��LO�5�+�h�����*K��ڳx���8{��+z�
metadata CHANGED
@@ -1,62 +1,91 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: noid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
5
- prerelease:
4
+ version: 0.6.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Chris Beer
9
8
  autorequire:
10
9
  bindir: bin
11
- cert_chain: []
12
- date: 2012-04-24 00:00:00.000000000 Z
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDaDCCAlCgAwIBAgIBATANBgkqhkiG9w0BAQUFADA9MQ4wDAYDVQQDDAVjaHJp
14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M172NHIwScyJdDFWxfBh1CTG9VRXTwQfyQmM0h1GThWYcdNw7
30
+ W4KPvarE4dgxT4TXIIKkh/K/Z9yaYt73biInVukEI9H2HHWkuAyblxg1jcR/zy+w
31
+ K27NJ2vhSpx2PPhb
32
+ -----END CERTIFICATE-----
33
+ date: 2013-03-08 00:00:00.000000000 Z
13
34
  dependencies:
14
35
  - !ruby/object:Gem::Dependency
15
36
  name: backports
16
37
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
38
  requirements:
19
- - - ! '>='
39
+ - - '>='
20
40
  - !ruby/object:Gem::Version
21
41
  version: '0'
22
42
  type: :runtime
23
43
  prerelease: false
24
44
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
45
  requirements:
27
- - - ! '>='
46
+ - - '>='
28
47
  - !ruby/object:Gem::Version
29
48
  version: '0'
30
49
  - !ruby/object:Gem::Dependency
31
50
  name: bundler
32
51
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
52
  requirements:
35
- - - ~>
53
+ - - '>='
36
54
  - !ruby/object:Gem::Version
37
- version: 1.1.0
55
+ version: '0'
38
56
  type: :development
39
57
  prerelease: false
40
58
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
59
  requirements:
43
- - - ~>
60
+ - - '>='
44
61
  - !ruby/object:Gem::Version
45
- version: 1.1.0
62
+ version: '0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: rake
65
+ requirement: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
46
77
  - !ruby/object:Gem::Dependency
47
78
  name: rspec
48
79
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
80
  requirements:
51
- - - ! '>='
81
+ - - '>='
52
82
  - !ruby/object:Gem::Version
53
83
  version: '2.0'
54
84
  type: :development
55
85
  prerelease: false
56
86
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
87
  requirements:
59
- - - ! '>='
88
+ - - '>='
60
89
  - !ruby/object:Gem::Version
61
90
  version: '2.0'
62
91
  description: ''
@@ -68,9 +97,10 @@ extra_rdoc_files: []
68
97
  files:
69
98
  - .gitignore
70
99
  - .rvmrc
100
+ - .travis.yml
71
101
  - Gemfile
72
102
  - LICENSE.txt
73
- - README.rdoc
103
+ - README.md
74
104
  - Rakefile
75
105
  - VERSION
76
106
  - lib/noid.rb
@@ -82,27 +112,26 @@ files:
82
112
  - spec/spec_helper.rb
83
113
  homepage: http://github.com/microservices/noid
84
114
  licenses: []
115
+ metadata: {}
85
116
  post_install_message:
86
117
  rdoc_options: []
87
118
  require_paths:
88
119
  - lib
89
120
  required_ruby_version: !ruby/object:Gem::Requirement
90
- none: false
91
121
  requirements:
92
- - - ! '>='
122
+ - - '>='
93
123
  - !ruby/object:Gem::Version
94
124
  version: '0'
95
125
  required_rubygems_version: !ruby/object:Gem::Requirement
96
- none: false
97
126
  requirements:
98
- - - ! '>='
127
+ - - '>='
99
128
  - !ruby/object:Gem::Version
100
129
  version: '0'
101
130
  requirements: []
102
131
  rubyforge_project: noid
103
- rubygems_version: 1.8.23
132
+ rubygems_version: 2.0.0
104
133
  signing_key:
105
- specification_version: 3
134
+ specification_version: 4
106
135
  summary: Nice Opaque Identifier
107
136
  test_files:
108
137
  - spec/lib/minter_spec.rb
metadata.gz.sig ADDED
Binary file