noid 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
data/lib/noid.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'noid/base'
2
+ require 'noid/minter'
2
3
  require 'noid/persistence'
4
+ require 'noid/persistence/base'
3
5
  require 'noid/persistence/json'
4
6
  require 'noid/identifier'
5
7
  require 'noid/identifier/singleton'
data/lib/noid/base.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'backports'
2
2
 
3
3
  module Noid
4
- class Base
4
+ module Base
5
5
  XDIGIT = ['0','1','2','3','4','5','6','7','8','9','b','c','d','f','g','h','j','k','l','n','p','q','r','s','t','v','w','x','z']
6
6
  MAX_COUNTERS = 293
7
7
 
@@ -0,0 +1,5 @@
1
+ module Noid
2
+ class Minter
3
+ include Noid::Base
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ module Noid::Persistence
2
+ class Base
3
+ include Noid::Base
4
+
5
+ def mint
6
+ a = super
7
+ save
8
+ return a
9
+ end
10
+ end
11
+ end
@@ -1,6 +1,6 @@
1
1
  require 'json'
2
2
  module Noid::Persistence
3
- class JSON < Noid::Base
3
+ class JSON < Base
4
4
  FILENAME = 'NOID.js'
5
5
  def initialize args = {}
6
6
  @file = args[:filename] || FILENAME
@@ -9,12 +9,6 @@ module Noid::Persistence
9
9
  save
10
10
  end
11
11
 
12
- def mint
13
- a = super
14
- save
15
- return a
16
- end
17
-
18
12
  protected
19
13
  def load_json
20
14
  data = ::JSON.parse(File.read(@file)) if File.exists? @file
data/noid.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{noid}
8
- s.version = "0.3.0"
8
+ s.version = "0.3.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Chris Beer"]
@@ -28,7 +28,9 @@ Gem::Specification.new do |s|
28
28
  "lib/noid/identifier.rb",
29
29
  "lib/noid/identifier/anvl.rb",
30
30
  "lib/noid/identifier/singleton.rb",
31
+ "lib/noid/minter.rb",
31
32
  "lib/noid/persistence.rb",
33
+ "lib/noid/persistence/base.rb",
32
34
  "lib/noid/persistence/json.rb",
33
35
  "noid.gemspec",
34
36
  "test/helper.rb",
data/test/test_binding.rb CHANGED
@@ -7,7 +7,7 @@ class TestNoidBinding < Test::Unit::TestCase
7
7
  should "accept identifier_class for NOID bindings" do
8
8
  Dir.mktmpdir do |d|
9
9
  Dir.chdir d
10
- n = Noid::Base.new :template => 'r.rek', :identifier => { :class => Noid::Identifier::Base }
10
+ n = Noid::Minter.new :template => 'r.rek', :identifier => { :class => Noid::Identifier::Base }
11
11
  id = n.mint
12
12
  assert_equal(Noid::Identifier::Base, id.class)
13
13
  id['abc'] = 123
@@ -18,7 +18,7 @@ class TestNoidBinding < Test::Unit::TestCase
18
18
  should "use singleton instance to persist NOID bindings" do
19
19
  Dir.mktmpdir do |d|
20
20
  Dir.chdir d
21
- n = Noid::Base.new :template => 'r.rek', :identifier => { :class => Noid::Identifier::Singleton }
21
+ n = Noid::Minter.new :template => 'r.rek', :identifier => { :class => Noid::Identifier::Singleton }
22
22
  id = n.mint
23
23
  id['abc'] = 123
24
24
  assert_equal(123, id['abc'])
@@ -31,7 +31,7 @@ class TestNoidBinding < Test::Unit::TestCase
31
31
  should "user anvl instance to persist NOID binding info" do
32
32
  Dir.mktmpdir do |d|
33
33
  Dir.chdir d
34
- n = Noid::Base.new :template => 'r.rek', :identifier => { :class => Noid::Identifier::Anvl }
34
+ n = Noid::Minter.new :template => 'r.rek', :identifier => { :class => Noid::Identifier::Anvl }
35
35
  id = n.mint
36
36
  id['abc'] = "123"
37
37
  assert_equal(Noid::Identifier::Anvl, id.class)
data/test/test_noid.rb CHANGED
@@ -3,31 +3,31 @@ require 'helper'
3
3
  class TestNoid < Test::Unit::TestCase
4
4
  context "Noid" do
5
5
  should "generate checkdigits correctly" do
6
- n = Noid::Base.new :template => 's.zd'
6
+ n = Noid::Minter.new :template => 's.zd'
7
7
  assert_equal('q', n.send(:checkdigit, '13030/xf93gt2'))
8
8
  end
9
9
 
10
10
  should "generate max sequence for type 'r'" do
11
- n = Noid::Base.new :template => 's.rd'
11
+ n = Noid::Minter.new :template => 's.rd'
12
12
  assert_equal(0, n.send(:min))
13
13
  assert_equal(10, n.send(:max))
14
14
 
15
- n = Noid::Base.new :template => 's.rdd'
15
+ n = Noid::Minter.new :template => 's.rdd'
16
16
  assert_equal(0, n.send(:min))
17
17
  assert_equal(100, n.send(:max))
18
18
  end
19
19
 
20
20
  should "generate quasi-random counters for type 'r'" do
21
- n = Noid::Base.new :template => 's.rd'
21
+ n = Noid::Minter.new :template => 's.rd'
22
22
  assert_equal((0..9).map { |x| {:value => x, :max => (x + 1)} }, n.instance_variable_get('@counters'))
23
23
 
24
- n = Noid::Base.new :template => 's.rdde'
24
+ n = Noid::Minter.new :template => 's.rdde'
25
25
  s = n.instance_variable_get('@counters')
26
26
  assert_contains(s, {:value => 2890, :max => 2900})
27
27
  end
28
28
 
29
29
  should "generate random sequence for type 'r'" do
30
- n = Noid::Base.new :template => 's.rd'
30
+ n = Noid::Minter.new :template => 's.rd'
31
31
  a = 10.times.map { |i| n.mint }
32
32
 
33
33
  10.times do |i|
@@ -37,14 +37,14 @@ class TestNoid < Test::Unit::TestCase
37
37
  end
38
38
 
39
39
  should "generate numeric sequence for type 's'" do
40
- n = Noid::Base.new :template => 's.sd'
40
+ n = Noid::Minter.new :template => 's.sd'
41
41
  10.times do |i|
42
42
  assert_equal("s#{i}", n.mint)
43
43
  end
44
44
  end
45
45
 
46
46
  should "generate extended sequence for type 's'" do
47
- n = Noid::Base.new :template => 's.se'
47
+ n = Noid::Minter.new :template => 's.se'
48
48
  10.times do |i|
49
49
  assert_equal("s#{i}", n.mint)
50
50
  end
@@ -55,7 +55,7 @@ class TestNoid < Test::Unit::TestCase
55
55
  end
56
56
 
57
57
  should "raise an exception when overflowing sequence" do
58
- n = Noid::Base.new :template => 's.sd'
58
+ n = Noid::Minter.new :template => 's.sd'
59
59
  10.times do |i|
60
60
  assert_equal("s#{i}", n.mint)
61
61
  end
@@ -66,20 +66,20 @@ class TestNoid < Test::Unit::TestCase
66
66
  end
67
67
 
68
68
  should "generate sequence for type 's' with checkdigit" do
69
- n = Noid::Base.new :template => 's.sdk'
69
+ n = Noid::Minter.new :template => 's.sdk'
70
70
  assert_equal('s0s', n.mint)
71
71
  assert_equal('s1v', n.mint)
72
72
  assert_equal('s2x', n.mint)
73
73
  end
74
74
 
75
75
  should "generate sequence for type 'z' with checkdigit" do
76
- n = Noid::Base.new :template => 'z.zdk'
76
+ n = Noid::Minter.new :template => 'z.zdk'
77
77
  assert_equal('z0z', n.mint)
78
78
  assert_equal('z11', n.mint)
79
79
  assert_equal('z23', n.mint)
80
80
  end
81
81
  should "generate sequence for type 'z', adding new digits as needed" do
82
- n = Noid::Base.new :template => 'z.zdk'
82
+ n = Noid::Minter.new :template => 'z.zdk'
83
83
  assert_equal('z0z', n.mint)
84
84
  assert_equal('z11', n.mint)
85
85
  assert_equal('z23', n.mint)
@@ -88,7 +88,7 @@ class TestNoid < Test::Unit::TestCase
88
88
  end
89
89
 
90
90
  should "generate sequence for type 'z', adding new xdigits as needed" do
91
- n = Noid::Base.new :template => 'z.zdek'
91
+ n = Noid::Minter.new :template => 'z.zdek'
92
92
  assert_equal('z00z', n.mint)
93
93
  assert_equal('z012', n.mint)
94
94
  assert_equal('z025', n.mint)
@@ -107,7 +107,7 @@ class TestNoid < Test::Unit::TestCase
107
107
  end
108
108
 
109
109
  should "validate 'r' digit sequences" do
110
- n = Noid::Base.new :template => 'r.rd'
110
+ n = Noid::Minter.new :template => 'r.rd'
111
111
 
112
112
  assert_equal(true, n.valid?('r1') )
113
113
  assert_equal(true, n.valid?('r9') )
@@ -117,7 +117,7 @@ class TestNoid < Test::Unit::TestCase
117
117
  end
118
118
 
119
119
  should "validate 'r' xdigit sequences" do
120
- n = Noid::Base.new :template => 'r.re'
120
+ n = Noid::Minter.new :template => 'r.re'
121
121
 
122
122
  assert_equal(true, n.valid?('r1') )
123
123
  assert_equal(true, n.valid?('r9') )
@@ -125,7 +125,7 @@ class TestNoid < Test::Unit::TestCase
125
125
  assert_equal(true, n.valid?('rb'))
126
126
  end
127
127
  should "validate 'r' xdigit + checkdigit sequences" do
128
- n = Noid::Base.new :template => 'r.rek'
128
+ n = Noid::Minter.new :template => 'r.rek'
129
129
 
130
130
  assert_equal(true, n.valid?('r2w') )
131
131
  assert_equal(false, n.valid?('r2b') )
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: noid
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 0
10
- version: 0.3.0
9
+ - 1
10
+ version: 0.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Chris Beer
@@ -141,7 +141,9 @@ files:
141
141
  - lib/noid/identifier.rb
142
142
  - lib/noid/identifier/anvl.rb
143
143
  - lib/noid/identifier/singleton.rb
144
+ - lib/noid/minter.rb
144
145
  - lib/noid/persistence.rb
146
+ - lib/noid/persistence/base.rb
145
147
  - lib/noid/persistence/json.rb
146
148
  - noid.gemspec
147
149
  - test/helper.rb