noid 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/VERSION +1 -1
- data/lib/noid.rb +3 -0
- data/lib/noid/identifier.rb +24 -0
- data/lib/noid/identifier/anvl.rb +32 -0
- data/lib/noid/identifier/singleton.rb +14 -0
- data/lib/noid/minter.rb +4 -1
- data/noid.gemspec +9 -1
- data/test/test_binding.rb +33 -0
- data/test/test_noid.rb +20 -0
- metadata +29 -10
data/Gemfile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/lib/noid.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Noid::Identifier
|
2
|
+
class Base
|
3
|
+
def initialize id
|
4
|
+
@id = id
|
5
|
+
@metadata = {}
|
6
|
+
end
|
7
|
+
|
8
|
+
def id
|
9
|
+
@id
|
10
|
+
end
|
11
|
+
|
12
|
+
def [] key
|
13
|
+
@metadata[key]
|
14
|
+
end
|
15
|
+
|
16
|
+
def []= key, value
|
17
|
+
@metadata[key] = value
|
18
|
+
end
|
19
|
+
|
20
|
+
def push hash
|
21
|
+
@metadata.merge! hash
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Noid::Identifier
|
2
|
+
class Anvl < Base
|
3
|
+
def initialize id
|
4
|
+
@id = id
|
5
|
+
@metadata = ::ANVL::Document.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def []= key, value
|
9
|
+
super
|
10
|
+
save
|
11
|
+
end
|
12
|
+
|
13
|
+
def push hash
|
14
|
+
@metadata << hash
|
15
|
+
save
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def file
|
20
|
+
@id
|
21
|
+
end
|
22
|
+
|
23
|
+
def save
|
24
|
+
File.open(file, 'w') do |f|
|
25
|
+
f.write @metadata.to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
data/lib/noid/minter.rb
CHANGED
@@ -8,6 +8,9 @@ module Noid
|
|
8
8
|
@max = nil
|
9
9
|
@min = nil
|
10
10
|
|
11
|
+
@identifier_class = args[:identifier_class]
|
12
|
+
@identifier_class ||= String
|
13
|
+
|
11
14
|
@prefix, @mask = args[:template].split('.')
|
12
15
|
|
13
16
|
@prefix = "#{args[:namespace]}/#{@prefix}" if args[:namespace]
|
@@ -55,7 +58,7 @@ module Noid
|
|
55
58
|
|
56
59
|
str += checkdigit(str) if @check
|
57
60
|
|
58
|
-
str
|
61
|
+
@identifier_class.new str
|
59
62
|
end
|
60
63
|
|
61
64
|
def valid? id
|
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.0
|
8
|
+
s.version = "0.1.0"
|
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"]
|
@@ -24,9 +24,13 @@ Gem::Specification.new do |s|
|
|
24
24
|
"Rakefile",
|
25
25
|
"VERSION",
|
26
26
|
"lib/noid.rb",
|
27
|
+
"lib/noid/identifier.rb",
|
28
|
+
"lib/noid/identifier/anvl.rb",
|
29
|
+
"lib/noid/identifier/singleton.rb",
|
27
30
|
"lib/noid/minter.rb",
|
28
31
|
"noid.gemspec",
|
29
32
|
"test/helper.rb",
|
33
|
+
"test/test_binding.rb",
|
30
34
|
"test/test_noid.rb"
|
31
35
|
]
|
32
36
|
s.homepage = %q{http://github.com/cbeer/noid}
|
@@ -36,6 +40,7 @@ Gem::Specification.new do |s|
|
|
36
40
|
s.summary = %q{Nice Opaque Identifier}
|
37
41
|
s.test_files = [
|
38
42
|
"test/helper.rb",
|
43
|
+
"test/test_binding.rb",
|
39
44
|
"test/test_noid.rb"
|
40
45
|
]
|
41
46
|
|
@@ -44,17 +49,20 @@ Gem::Specification.new do |s|
|
|
44
49
|
s.specification_version = 3
|
45
50
|
|
46
51
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
52
|
+
s.add_runtime_dependency(%q<anvl>, [">= 0"])
|
47
53
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
48
54
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
49
55
|
s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
|
50
56
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
51
57
|
else
|
58
|
+
s.add_dependency(%q<anvl>, [">= 0"])
|
52
59
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
53
60
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
54
61
|
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
55
62
|
s.add_dependency(%q<rcov>, [">= 0"])
|
56
63
|
end
|
57
64
|
else
|
65
|
+
s.add_dependency(%q<anvl>, [">= 0"])
|
58
66
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
59
67
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
60
68
|
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'anvl'
|
3
|
+
|
4
|
+
class TestNoidBinding < Test::Unit::TestCase
|
5
|
+
context "Noid" do
|
6
|
+
should "accept identifier_class for NOID bindings" do
|
7
|
+
n = Noid::Minter.new :template => 'r.rek', :identifier_class => Noid::Identifier::Base
|
8
|
+
id = n.mint
|
9
|
+
assert_equal(Noid::Identifier::Base, id.class)
|
10
|
+
id['abc'] = 123
|
11
|
+
assert_equal(123, id['abc'])
|
12
|
+
end
|
13
|
+
|
14
|
+
should "use singleton instance to persist NOID bindings" do
|
15
|
+
n = Noid::Minter.new :template => 'r.rek', :identifier_class => Noid::Identifier::Singleton
|
16
|
+
id = n.mint
|
17
|
+
id['abc'] = 123
|
18
|
+
assert_equal(123, id['abc'])
|
19
|
+
|
20
|
+
id2 = Noid::Identifier::Singleton.new id.id
|
21
|
+
assert_equal(123, id2['abc'])
|
22
|
+
end
|
23
|
+
|
24
|
+
should "user anvl instance to persist NOID binding info" do
|
25
|
+
n = Noid::Minter.new :template => 'r.rek', :identifier_class => Noid::Identifier::Anvl
|
26
|
+
id = n.mint
|
27
|
+
id['abc'] = 123
|
28
|
+
assert_equal(Noid::Identifier::Anvl, id.class)
|
29
|
+
assert_equal("123", id['abc'])
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/test/test_noid.rb
CHANGED
@@ -130,5 +130,25 @@ class TestNoid < Test::Unit::TestCase
|
|
130
130
|
assert_equal(true, n.valid?('r2w') )
|
131
131
|
assert_equal(false, n.valid?('r2b') )
|
132
132
|
end
|
133
|
+
|
134
|
+
should "accept identifier_class for NOID bindings" do
|
135
|
+
n = Noid::Minter.new :template => 'r.rek', :identifier_class => Noid::Identifier::Base
|
136
|
+
id = n.mint
|
137
|
+
assert_equal(Noid::Identifier::Base, id.class)
|
138
|
+
id['abc'] = 123
|
139
|
+
assert_equal(123, id['abc'])
|
140
|
+
end
|
141
|
+
|
142
|
+
should "use singleton instance to persist NOID bindings" do
|
143
|
+
n = Noid::Minter.new :template => 'r.rek', :identifier_class => Noid::Identifier::Singleton
|
144
|
+
id = n.mint
|
145
|
+
id['abc'] = 123
|
146
|
+
assert_equal(123, id['abc'])
|
147
|
+
|
148
|
+
id2 = Noid::Identifier::Singleton.new id.id
|
149
|
+
assert_equal(123, id2['abc'])
|
150
|
+
end
|
151
|
+
|
152
|
+
|
133
153
|
end
|
134
154
|
end
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.2
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Chris Beer
|
@@ -19,9 +19,9 @@ date: 2010-12-12 00:00:00 -05:00
|
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
type: :
|
22
|
+
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
name:
|
24
|
+
name: anvl
|
25
25
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
26
26
|
none: false
|
27
27
|
requirements:
|
@@ -35,8 +35,22 @@ dependencies:
|
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
type: :development
|
37
37
|
prerelease: false
|
38
|
-
name:
|
38
|
+
name: shoulda
|
39
39
|
version_requirements: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
version: "0"
|
48
|
+
requirement: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
name: bundler
|
53
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
40
54
|
none: false
|
41
55
|
requirements:
|
42
56
|
- - ~>
|
@@ -47,12 +61,12 @@ dependencies:
|
|
47
61
|
- 0
|
48
62
|
- 0
|
49
63
|
version: 1.0.0
|
50
|
-
requirement: *
|
64
|
+
requirement: *id003
|
51
65
|
- !ruby/object:Gem::Dependency
|
52
66
|
type: :development
|
53
67
|
prerelease: false
|
54
68
|
name: jeweler
|
55
|
-
version_requirements: &
|
69
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
56
70
|
none: false
|
57
71
|
requirements:
|
58
72
|
- - ~>
|
@@ -63,12 +77,12 @@ dependencies:
|
|
63
77
|
- 5
|
64
78
|
- 1
|
65
79
|
version: 1.5.1
|
66
|
-
requirement: *
|
80
|
+
requirement: *id004
|
67
81
|
- !ruby/object:Gem::Dependency
|
68
82
|
type: :development
|
69
83
|
prerelease: false
|
70
84
|
name: rcov
|
71
|
-
version_requirements: &
|
85
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
72
86
|
none: false
|
73
87
|
requirements:
|
74
88
|
- - ">="
|
@@ -77,7 +91,7 @@ dependencies:
|
|
77
91
|
segments:
|
78
92
|
- 0
|
79
93
|
version: "0"
|
80
|
-
requirement: *
|
94
|
+
requirement: *id005
|
81
95
|
description: ""
|
82
96
|
email: chris@cbeer.info
|
83
97
|
executables: []
|
@@ -95,9 +109,13 @@ files:
|
|
95
109
|
- Rakefile
|
96
110
|
- VERSION
|
97
111
|
- lib/noid.rb
|
112
|
+
- lib/noid/identifier.rb
|
113
|
+
- lib/noid/identifier/anvl.rb
|
114
|
+
- lib/noid/identifier/singleton.rb
|
98
115
|
- lib/noid/minter.rb
|
99
116
|
- noid.gemspec
|
100
117
|
- test/helper.rb
|
118
|
+
- test/test_binding.rb
|
101
119
|
- test/test_noid.rb
|
102
120
|
has_rdoc: true
|
103
121
|
homepage: http://github.com/cbeer/noid
|
@@ -135,4 +153,5 @@ specification_version: 3
|
|
135
153
|
summary: Nice Opaque Identifier
|
136
154
|
test_files:
|
137
155
|
- test/helper.rb
|
156
|
+
- test/test_binding.rb
|
138
157
|
- test/test_noid.rb
|