pebbles-uid 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +20 -17
- data/lib/pebbles-uid.rb +26 -63
- data/lib/pebbles-uid/class_methods.rb +62 -0
- data/lib/pebbles-uid/query.rb +22 -22
- data/lib/pebbles-uid/version.rb +1 -1
- data/spec/query_spec.rb +16 -21
- data/spec/uid_spec.rb +19 -10
- metadata +4 -5
- data/lib/pebbles-uid/cache_key.rb +0 -13
- data/lib/pebbles-uid/parse.rb +0 -14
data/README.md
CHANGED
@@ -4,21 +4,21 @@ Handle unique identifiers in the Pebblestack universe conveniently.
|
|
4
4
|
|
5
5
|
## Unique Identifiers
|
6
6
|
|
7
|
-
A valid Uid is in the format `genus[.
|
7
|
+
A valid Uid is in the format `genus[.epiteth]:path[$oid]`.
|
8
8
|
|
9
|
-
###
|
9
|
+
### Species
|
10
10
|
|
11
|
-
The
|
11
|
+
The species is one or more dot-delimited labels.
|
12
12
|
|
13
|
-
The first label uniquely identifies which pebble the resource originated from.
|
13
|
+
The first label, the genus, uniquely identifies which pebble the resource originated from.
|
14
14
|
|
15
|
-
Any secondary labels are grouped into
|
15
|
+
Any secondary labels are grouped into an `epiteth`, which identify sub-types within a given pebble.
|
16
16
|
|
17
17
|
```
|
18
18
|
post.doc
|
19
19
|
```
|
20
20
|
|
21
|
-
Here the genus is `post`, and the
|
21
|
+
Here the genus is `post`, and the epiteth is `doc`.
|
22
22
|
|
23
23
|
### Path
|
24
24
|
|
@@ -35,7 +35,7 @@ post.card:tourism.norway.west-coast$42
|
|
35
35
|
|
36
36
|
The object identifier can be nearly any string, including another uid.
|
37
37
|
|
38
|
-
The oid _MUST_ be unique for any
|
38
|
+
The oid _MUST_ be unique for any species and realm.
|
39
39
|
|
40
40
|
There are currently two characters which cannot be included in an oid:
|
41
41
|
|
@@ -49,19 +49,19 @@ Oid is optional when creating a new resource.
|
|
49
49
|
|
50
50
|
Across the pebblestack universe, you can query for a specific resource by passing a full Uid.
|
51
51
|
|
52
|
-
In addition, the wildcard query `
|
52
|
+
In addition, the wildcard query `species:realm.*$oid` will identify a single resource, e.g.:
|
53
53
|
|
54
54
|
```
|
55
55
|
post.card:tourism.*$42
|
56
56
|
```
|
57
57
|
|
58
|
-
If a specific resource is targeted (i.e.
|
58
|
+
If a specific resource is targeted (i.e. species and oid are both unambiguous), then realm is required.
|
59
59
|
|
60
60
|
### For a collection of resources
|
61
61
|
|
62
62
|
#### Asterisks
|
63
63
|
|
64
|
-
The most permissive query consists of any
|
64
|
+
The most permissive query consists of any species in any path, with any oid (implied):
|
65
65
|
|
66
66
|
```
|
67
67
|
*:*
|
@@ -75,7 +75,7 @@ This is the equivalent to:
|
|
75
75
|
|
76
76
|
Queries may not be made across multiple realms at one time. If realm is not specified in the path, then it is assumed that the application verifies realm if necessary.
|
77
77
|
|
78
|
-
In the context of a
|
78
|
+
In the context of a species or a path, you may specify any number of labels and terminate with an asterisk, which means: zero or more labels follow. E.g.:
|
79
79
|
|
80
80
|
```
|
81
81
|
post.*:tourism.europe.*
|
@@ -99,7 +99,7 @@ In the context of an oid, you either know the oid you want, or you don't. A quer
|
|
99
99
|
|
100
100
|
A pipe signifies _or_.
|
101
101
|
|
102
|
-
This can be used in
|
102
|
+
This can be used in species at any position:
|
103
103
|
|
104
104
|
```
|
105
105
|
unit|group:*
|
@@ -139,7 +139,7 @@ NOTE: realm is required in this case, because each term in the list must refer t
|
|
139
139
|
|
140
140
|
#### Caret
|
141
141
|
|
142
|
-
In both
|
142
|
+
In both species and paths, a caret indicates ancestry up to the specified point:
|
143
143
|
|
144
144
|
```
|
145
145
|
post:realm.europe.^norway.fjords.food
|
@@ -178,10 +178,13 @@ uid = Pebbles::Uid.new('post.card:tourism.norway.fjords$1234')
|
|
178
178
|
uid.realm
|
179
179
|
=> "tourism"
|
180
180
|
|
181
|
-
uid.
|
181
|
+
uid.species
|
182
182
|
=> "post.card"
|
183
183
|
|
184
|
-
uid.
|
184
|
+
uid.genus
|
185
|
+
=> "post"
|
186
|
+
|
187
|
+
uid.epiteth
|
185
188
|
=> "card"
|
186
189
|
|
187
190
|
uid.path
|
@@ -194,7 +197,7 @@ uid.to_s
|
|
194
197
|
=> 'post.card:tourism.norway.fjords$1234'
|
195
198
|
|
196
199
|
uid.to_hash
|
197
|
-
=> {'
|
200
|
+
=> {'species_0' => 'post', 'species_1' => 'card', 'path_0' => 'tourism', 'path_1' => 'norway', 'path_2' => 'fjords', 'oid' => '1234'}
|
198
201
|
```
|
199
202
|
|
200
203
|
### Uid Queries
|
@@ -209,7 +212,7 @@ query.collection?
|
|
209
212
|
=> true
|
210
213
|
|
211
214
|
query.to_hash
|
212
|
-
=> {'
|
215
|
+
=> {'species_0' => 'post', 'species_1' => 'card', 'path_0' => 'tourism', 'path_1' => ['norway', nil], ['fjords', 'mountains', nil]}
|
213
216
|
```
|
214
217
|
|
215
218
|
## TODO
|
data/lib/pebbles-uid.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
require "pebbles-uid/version"
|
2
2
|
|
3
3
|
require 'pebbles-uid/wildcard'
|
4
|
-
require 'pebbles-uid/
|
5
|
-
require 'pebbles-uid/cache_key'
|
4
|
+
require 'pebbles-uid/class_methods'
|
6
5
|
require 'pebbles-uid/query'
|
7
6
|
require "pebbles-uid/conditions"
|
8
7
|
require "pebbles-uid/labels"
|
@@ -11,56 +10,11 @@ require "pebbles-uid/oid"
|
|
11
10
|
module Pebbles
|
12
11
|
class Uid
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
def parse(s)
|
17
|
-
/^(?<genus>.*):(?<path>[^\$]*)\$?(?<oid>.*)$/ =~ s
|
18
|
-
[genus, path, oid.empty? ? nil : oid]
|
19
|
-
end
|
20
|
-
|
21
|
-
def build(genus, path, oid)
|
22
|
-
s = "#{genus}:#{path}"
|
23
|
-
s << "$#{oid}" if oid
|
24
|
-
s
|
25
|
-
end
|
26
|
-
|
27
|
-
def query(s, options = {})
|
28
|
-
Pebbles::Uid::Query.new(s, options)
|
29
|
-
end
|
30
|
-
|
31
|
-
def genus(s)
|
32
|
-
parse(s)[0]
|
33
|
-
end
|
34
|
-
|
35
|
-
def path(s)
|
36
|
-
parse(s)[1]
|
37
|
-
end
|
38
|
-
|
39
|
-
def oid(s)
|
40
|
-
parse(s)[2]
|
41
|
-
end
|
42
|
-
|
43
|
-
def valid_path?(path)
|
44
|
-
return false if path.empty?
|
45
|
-
Labels.new(path).valid_with?(/^[a-z0-9_-]+$/)
|
46
|
-
end
|
47
|
-
|
48
|
-
def valid_genus?(genus)
|
49
|
-
return false if genus.empty?
|
50
|
-
Labels.new(genus).valid_with?(/^[a-z0-9_-]+$/)
|
51
|
-
end
|
52
|
-
|
53
|
-
def valid_oid?(oid)
|
54
|
-
return true if !oid || oid.empty?
|
55
|
-
!!(oid =~ /^[^,|]+$/)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
attr_reader :genus, :path, :oid
|
13
|
+
attr_reader :species, :path, :oid
|
60
14
|
def initialize(s)
|
61
|
-
@
|
62
|
-
unless
|
63
|
-
raise ArgumentError.new("Invalid Uid: #{s}.
|
15
|
+
@species, @path, @oid = self.class.parse(s)
|
16
|
+
unless valid_species?
|
17
|
+
raise ArgumentError.new("Invalid Uid: #{s}. Species is invalid.")
|
64
18
|
end
|
65
19
|
unless valid_path?
|
66
20
|
raise ArgumentError.new("Invalid Uid: #{s}. Path is invalid.")
|
@@ -70,12 +24,21 @@ module Pebbles
|
|
70
24
|
raise ArgumentError.new("Invalid Uid: #{s}. Cannot have wildcard oid.")
|
71
25
|
end
|
72
26
|
|
73
|
-
if
|
74
|
-
raise ArgumentError.new("Invalid Uid: #{s}.
|
27
|
+
if species.empty?
|
28
|
+
raise ArgumentError.new("Invalid Uid: #{s}. Species is required.")
|
75
29
|
end
|
76
30
|
if path.empty?
|
77
31
|
raise ArgumentError.new("Invalid Uid: #{s}. Realm is required.")
|
78
32
|
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
def epiteth
|
37
|
+
@epiteth ||= species.split('.')[1..-1].join('.')
|
38
|
+
end
|
39
|
+
|
40
|
+
def genus
|
41
|
+
@genus ||= species.split('.').first
|
79
42
|
end
|
80
43
|
|
81
44
|
def realm
|
@@ -83,23 +46,23 @@ module Pebbles
|
|
83
46
|
end
|
84
47
|
|
85
48
|
def species
|
86
|
-
@species ||=
|
49
|
+
@species ||= species_labels.tail.join('.')
|
87
50
|
end
|
88
51
|
|
89
52
|
def path_labels
|
90
53
|
@path_labels ||= Labels.new(path, :name => 'path')
|
91
54
|
end
|
92
55
|
|
93
|
-
def
|
94
|
-
@
|
56
|
+
def species_labels
|
57
|
+
@species_labels ||= Labels.new(species, :name => 'species')
|
95
58
|
end
|
96
59
|
|
97
60
|
def valid?
|
98
|
-
|
61
|
+
valid_species? && valid_path? && valid_oid?
|
99
62
|
end
|
100
63
|
|
101
|
-
def
|
102
|
-
self.class.
|
64
|
+
def valid_species?
|
65
|
+
self.class.valid_species?(species)
|
103
66
|
end
|
104
67
|
|
105
68
|
def valid_path?
|
@@ -115,21 +78,21 @@ module Pebbles
|
|
115
78
|
end
|
116
79
|
|
117
80
|
def to_s
|
118
|
-
Pebbles::Uid.build
|
81
|
+
Pebbles::Uid.build species, path, oid
|
119
82
|
end
|
120
83
|
|
121
84
|
def parsed
|
122
|
-
[
|
85
|
+
[species, path, oid].compact
|
123
86
|
end
|
124
87
|
|
125
88
|
def to_hash
|
126
|
-
hash =
|
89
|
+
hash = species_labels.to_hash.merge(path_labels.to_hash)
|
127
90
|
hash = hash.merge(:oid => oid) if oid?
|
128
91
|
hash
|
129
92
|
end
|
130
93
|
|
131
94
|
def cache_key
|
132
|
-
"#{
|
95
|
+
"#{species}:#{realm}.*$#{oid}"
|
133
96
|
end
|
134
97
|
|
135
98
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Pebbles
|
2
|
+
class Uid
|
3
|
+
class << self
|
4
|
+
|
5
|
+
def parse(s)
|
6
|
+
/^(?<species>.*):(?<path>[^\$]*)\$?(?<oid>.*)$/ =~ s
|
7
|
+
[species, path, oid.empty? ? nil : oid]
|
8
|
+
end
|
9
|
+
|
10
|
+
def build(species, path, oid)
|
11
|
+
s = "#{species}:#{path}"
|
12
|
+
s << "$#{oid}" if oid
|
13
|
+
s
|
14
|
+
end
|
15
|
+
|
16
|
+
def query(s, options = {})
|
17
|
+
Pebbles::Uid::Query.new(s, options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def cache_key(uid)
|
21
|
+
species, path, oid = parse(uid)
|
22
|
+
"#{species}:#{Labels.new(path).first}.*$#{oid}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def species(s)
|
26
|
+
parse(s)[0]
|
27
|
+
end
|
28
|
+
|
29
|
+
def genus(s)
|
30
|
+
parse(s)[0].split('.').first
|
31
|
+
end
|
32
|
+
|
33
|
+
def epiteth(s)
|
34
|
+
parse(s)[0].split('.')[1..-1].join('.')
|
35
|
+
end
|
36
|
+
|
37
|
+
def path(s)
|
38
|
+
parse(s)[1]
|
39
|
+
end
|
40
|
+
|
41
|
+
def oid(s)
|
42
|
+
parse(s)[2]
|
43
|
+
end
|
44
|
+
|
45
|
+
def valid_path?(path)
|
46
|
+
return false if path.empty?
|
47
|
+
Labels.new(path).valid_with?(/^[a-z0-9_-]+$/)
|
48
|
+
end
|
49
|
+
|
50
|
+
def valid_species?(species)
|
51
|
+
return false if species.empty?
|
52
|
+
Labels.new(species).valid_with?(/^[a-z0-9_-]+$/)
|
53
|
+
end
|
54
|
+
|
55
|
+
def valid_oid?(oid)
|
56
|
+
return true if !oid || oid.empty?
|
57
|
+
!!(oid =~ /^[^,|]+$/)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
data/lib/pebbles-uid/query.rb
CHANGED
@@ -4,11 +4,11 @@ module Pebbles
|
|
4
4
|
|
5
5
|
NO_MARKER = Class.new
|
6
6
|
|
7
|
-
attr_reader :term, :terms, :
|
8
|
-
:
|
7
|
+
attr_reader :term, :terms, :species, :path, :oid,
|
8
|
+
:species_name, :path_name, :suffix, :stop
|
9
9
|
def initialize(term, options = {})
|
10
10
|
@term = term
|
11
|
-
@
|
11
|
+
@species_name = options.fetch(:species) { 'species' }
|
12
12
|
@path_name = options.fetch(:path) { 'path' }
|
13
13
|
@suffix = options[:suffix]
|
14
14
|
@stop = options.fetch(:stop) { NO_MARKER }
|
@@ -20,7 +20,7 @@ module Pebbles
|
|
20
20
|
end
|
21
21
|
|
22
22
|
if !list?
|
23
|
-
@
|
23
|
+
@species, @path, @oid = Pebbles::Uid.parse(term)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -47,16 +47,16 @@ module Pebbles
|
|
47
47
|
@path && @path.split('.').reject {|s| s == '*'}.length > 0
|
48
48
|
end
|
49
49
|
|
50
|
-
def
|
51
|
-
@
|
50
|
+
def species?
|
51
|
+
@species && @species != '*'
|
52
52
|
end
|
53
53
|
|
54
|
-
def
|
55
|
-
!
|
54
|
+
def epiteth?
|
55
|
+
!species_wrapper.tail.empty?
|
56
56
|
end
|
57
57
|
|
58
|
-
def
|
59
|
-
|
58
|
+
def epiteth
|
59
|
+
species_wrapper.tail.join('.')
|
60
60
|
end
|
61
61
|
|
62
62
|
def oid?
|
@@ -72,7 +72,7 @@ module Pebbles
|
|
72
72
|
raise RuntimeError.new('Cannot compute a conditions hash for a list of uids')
|
73
73
|
end
|
74
74
|
|
75
|
-
hash =
|
75
|
+
hash = species_wrapper.to_hash.merge(path_wrapper.to_hash)
|
76
76
|
if oid?
|
77
77
|
oid_key = ['oid', suffix].compact.join('_').to_sym
|
78
78
|
hash = hash.merge(oid_key => oid)
|
@@ -86,13 +86,13 @@ module Pebbles
|
|
86
86
|
|
87
87
|
private
|
88
88
|
|
89
|
-
def
|
90
|
-
unless @
|
91
|
-
options = {:name =>
|
89
|
+
def species_wrapper
|
90
|
+
unless @species_wrapper
|
91
|
+
options = {:name => species_name, :suffix => suffix}
|
92
92
|
options.merge!(:stop => stop) if use_stop_marker?
|
93
|
-
@
|
93
|
+
@species_wrapper = Labels.new(species, options)
|
94
94
|
end
|
95
|
-
@
|
95
|
+
@species_wrapper
|
96
96
|
end
|
97
97
|
|
98
98
|
def path_wrapper
|
@@ -106,21 +106,21 @@ module Pebbles
|
|
106
106
|
|
107
107
|
def wildcard_query?
|
108
108
|
return false if term.include?(',')
|
109
|
-
|
110
|
-
return true if Labels.new(
|
109
|
+
species, _, oid = Pebbles::Uid.parse(term)
|
110
|
+
return true if Labels.new(species).wildcard?
|
111
111
|
return true if oid.nil? || oid.empty? || oid == '*'
|
112
112
|
false
|
113
113
|
end
|
114
114
|
|
115
115
|
def extract_terms
|
116
116
|
term.split(',').map do |uid|
|
117
|
-
|
118
|
-
|
117
|
+
_species, _path, _oid = Pebbles::Uid.parse(uid)
|
118
|
+
species_labels = Labels.new(_species)
|
119
119
|
path_labels = Labels.new(_path)
|
120
120
|
oid_box = Oid.new(_oid)
|
121
121
|
|
122
122
|
raise ArgumentError.new('Realm must be specified') if path_labels.empty? || path_labels.first == '*'
|
123
|
-
raise ArgumentError.new('
|
123
|
+
raise ArgumentError.new('Species must unambiguous') if species_labels.ambiguous?
|
124
124
|
raise ArgumentError.new('Oid must be unambiguous') if oid_box.ambiguous?
|
125
125
|
|
126
126
|
@realm ||= path_labels.first
|
@@ -128,7 +128,7 @@ module Pebbles
|
|
128
128
|
|
129
129
|
if oid_box.multiple?
|
130
130
|
_oid.split('|').map do |s|
|
131
|
-
"#{
|
131
|
+
"#{_species}:#{_path}$#{s}"
|
132
132
|
end
|
133
133
|
else
|
134
134
|
uid
|
data/lib/pebbles-uid/version.rb
CHANGED
data/spec/query_spec.rb
CHANGED
@@ -1,9 +1,4 @@
|
|
1
|
-
require 'pebbles-uid
|
2
|
-
require 'pebbles-uid/cache_key'
|
3
|
-
require 'pebbles-uid/labels'
|
4
|
-
require 'pebbles-uid/conditions'
|
5
|
-
require 'pebbles-uid/oid'
|
6
|
-
require 'pebbles-uid/query'
|
1
|
+
require 'pebbles-uid'
|
7
2
|
|
8
3
|
describe Pebbles::Uid::Query do
|
9
4
|
|
@@ -17,7 +12,7 @@ describe Pebbles::Uid::Query do
|
|
17
12
|
its(:list?) { should == false }
|
18
13
|
its(:collection?) { should == false }
|
19
14
|
its(:cache_keys) { should eq(['post:area51.*$abc']) }
|
20
|
-
its(:to_hash) { should eq(:
|
15
|
+
its(:to_hash) { should eq(:species_0_ => 'post', :path_0_ => 'area51', :oid_ => 'abc') }
|
21
16
|
|
22
17
|
it "handles a wildcard path if realm is given" do
|
23
18
|
query = Pebbles::Uid::Query.new('post:area51.*$abc')
|
@@ -73,7 +68,7 @@ describe Pebbles::Uid::Query do
|
|
73
68
|
->{ Pebbles::Uid::Query.new('post:area51$abc,post:area52$xyz') }.should raise_error(ArgumentError)
|
74
69
|
end
|
75
70
|
|
76
|
-
it "bails with unspecific
|
71
|
+
it "bails with unspecific species" do
|
77
72
|
->{ Pebbles::Uid::Query.new('post.*:area51$abc,post:area51$xyz') }.should raise_error(ArgumentError)
|
78
73
|
end
|
79
74
|
|
@@ -101,7 +96,7 @@ describe Pebbles::Uid::Query do
|
|
101
96
|
context "everything" do
|
102
97
|
subject { Pebbles::Uid::Query.new('*:*') }
|
103
98
|
|
104
|
-
its(:
|
99
|
+
its(:species?) { should == false }
|
105
100
|
its(:path?) { should == false }
|
106
101
|
its(:oid?) { should == false }
|
107
102
|
|
@@ -115,25 +110,25 @@ describe Pebbles::Uid::Query do
|
|
115
110
|
context "everything, with any oid" do
|
116
111
|
subject { Pebbles::Uid::Query.new('*:*$*') }
|
117
112
|
|
118
|
-
its(:
|
113
|
+
its(:species?) { should == false }
|
119
114
|
its(:path?) { should == false }
|
120
115
|
its(:oid?) { should == false }
|
121
116
|
its(:to_hash) { should == {} }
|
122
117
|
end
|
123
118
|
|
124
|
-
context "a
|
119
|
+
context "a species" do
|
125
120
|
subject { Pebbles::Uid::Query.new('beast:*$*') }
|
126
|
-
its(:
|
127
|
-
its(:
|
128
|
-
its(:
|
129
|
-
its(:to_hash) { should == {:
|
121
|
+
its(:species?) { should == true }
|
122
|
+
its(:species) { should eq('beast') }
|
123
|
+
its(:epiteth?) { should == false }
|
124
|
+
its(:to_hash) { should == {:species_0 => 'beast'} }
|
130
125
|
end
|
131
126
|
|
132
|
-
context "a
|
127
|
+
context "a epiteth" do
|
133
128
|
subject { Pebbles::Uid::Query.new('beast.mythical.hairy:*$*') }
|
134
|
-
its(:
|
135
|
-
its(:
|
136
|
-
its(:to_hash) { should == {:
|
129
|
+
its(:epiteth?) { should == true }
|
130
|
+
its(:epiteth) { should eq('mythical.hairy') }
|
131
|
+
its(:to_hash) { should == {:species_0 => 'beast', :species_1 => 'mythical', :species_2 => 'hairy'} }
|
137
132
|
end
|
138
133
|
|
139
134
|
context "a path" do
|
@@ -150,7 +145,7 @@ describe Pebbles::Uid::Query do
|
|
150
145
|
end
|
151
146
|
|
152
147
|
context "a typical search" do
|
153
|
-
subject { Pebbles::Uid::Query.new('beast:myths.*', :
|
148
|
+
subject { Pebbles::Uid::Query.new('beast:myths.*', :species => 'klass', :path => 'label', :suffix => '') }
|
154
149
|
its(:to_hash) { should == {:klass_0_ => 'beast', :label_0_ => 'myths'} }
|
155
150
|
its(:next_path_label) { should == :label_1_ }
|
156
151
|
end
|
@@ -162,7 +157,7 @@ describe Pebbles::Uid::Query do
|
|
162
157
|
end
|
163
158
|
|
164
159
|
context "a search with stops" do
|
165
|
-
subject { Pebbles::Uid::Query.new('beast:myths$*', :
|
160
|
+
subject { Pebbles::Uid::Query.new('beast:myths$*', :species => 'klass', :path => 'label', :suffix => '', :stop => nil) }
|
166
161
|
its(:to_hash) { should == {:klass_0_ => 'beast', :klass_1_ => nil, :label_0_ => 'myths', :label_1_ => nil} }
|
167
162
|
its(:next_path_label) { should == :label_1_ }
|
168
163
|
end
|
data/spec/uid_spec.rb
CHANGED
@@ -14,7 +14,15 @@ describe Pebbles::Uid do
|
|
14
14
|
|
15
15
|
describe "extracts elements" do
|
16
16
|
specify "genus" do
|
17
|
-
Pebbles::Uid.genus(uid).should eq('post
|
17
|
+
Pebbles::Uid.genus(uid).should eq('post')
|
18
|
+
end
|
19
|
+
|
20
|
+
specify "species" do
|
21
|
+
Pebbles::Uid.species(uid).should eq('post.card')
|
22
|
+
end
|
23
|
+
|
24
|
+
specify "epiteth" do
|
25
|
+
Pebbles::Uid.epiteth('post.picture.card:a.b.c$1').should eq('picture.card')
|
18
26
|
end
|
19
27
|
|
20
28
|
specify "path" do
|
@@ -31,7 +39,7 @@ describe Pebbles::Uid do
|
|
31
39
|
end
|
32
40
|
|
33
41
|
describe "must" do
|
34
|
-
specify "have a
|
42
|
+
specify "have a species" do
|
35
43
|
->{ Pebbles::Uid.new(':tourism.norway$1') }.should raise_error(ArgumentError)
|
36
44
|
end
|
37
45
|
|
@@ -47,7 +55,7 @@ describe Pebbles::Uid do
|
|
47
55
|
end
|
48
56
|
|
49
57
|
describe "rejects" do
|
50
|
-
it "wildcard
|
58
|
+
it "wildcard species" do
|
51
59
|
->{ Pebbles::Uid.new('post.*:tourism$1') }.should raise_error(ArgumentError)
|
52
60
|
->{ Pebbles::Uid.new('post|card:tourism$1') }.should raise_error(ArgumentError)
|
53
61
|
->{ Pebbles::Uid.new('post.^b.c:tourism$1') }.should raise_error(ArgumentError)
|
@@ -78,10 +86,10 @@ describe Pebbles::Uid do
|
|
78
86
|
end
|
79
87
|
end
|
80
88
|
|
81
|
-
context "
|
89
|
+
context "species" do
|
82
90
|
%w(- . _ 8).each do |char|
|
83
|
-
it "accepts #{char} in a
|
84
|
-
Pebbles::Uid.
|
91
|
+
it "accepts #{char} in a species" do
|
92
|
+
Pebbles::Uid.valid_species?("uni#{char}corn").should == true
|
85
93
|
end
|
86
94
|
end
|
87
95
|
|
@@ -120,8 +128,9 @@ describe Pebbles::Uid do
|
|
120
128
|
|
121
129
|
its(:to_s) { should eq(uid) }
|
122
130
|
its(:realm) { should eq('tourism') }
|
123
|
-
its(:genus) { should eq('post
|
124
|
-
its(:species) { should eq('card') }
|
131
|
+
its(:genus) { should eq('post') }
|
132
|
+
its(:species) { should eq('post.card') }
|
133
|
+
its(:epiteth) { should eq('card') }
|
125
134
|
its(:path) { should eq('tourism.norway.fjords') }
|
126
135
|
its(:oid) { should eq('1234') }
|
127
136
|
its(:oid?) { should == true }
|
@@ -129,12 +138,12 @@ describe Pebbles::Uid do
|
|
129
138
|
its(:cache_key) { should eq('post.card:tourism.*$1234') }
|
130
139
|
|
131
140
|
its(:to_hash) do
|
132
|
-
should eq(:
|
141
|
+
should eq(:species_0 => 'post', :species_1 => 'card', :path_0 => 'tourism', :path_1 => 'norway', :path_2 => 'fjords', :oid => '1234')
|
133
142
|
end
|
134
143
|
|
135
144
|
context "without an oid" do
|
136
145
|
it "excludes the oid key from the hash" do
|
137
|
-
Pebbles::Uid.new('post.doc:a.b.c').to_hash.should eq(:
|
146
|
+
Pebbles::Uid.new('post.doc:a.b.c').to_hash.should eq(:species_0 => 'post', :species_1 => 'doc', :path_0 => 'a', :path_1 => 'b', :path_2 => 'c')
|
138
147
|
end
|
139
148
|
end
|
140
149
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pebbles-uid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-10-16 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70250797645480 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70250797645480
|
25
25
|
description: Handle pebble UIDs conveniently.
|
26
26
|
email:
|
27
27
|
- katrina.owen@gmail.com
|
@@ -35,11 +35,10 @@ files:
|
|
35
35
|
- README.md
|
36
36
|
- Rakefile
|
37
37
|
- lib/pebbles-uid.rb
|
38
|
-
- lib/pebbles-uid/
|
38
|
+
- lib/pebbles-uid/class_methods.rb
|
39
39
|
- lib/pebbles-uid/conditions.rb
|
40
40
|
- lib/pebbles-uid/labels.rb
|
41
41
|
- lib/pebbles-uid/oid.rb
|
42
|
-
- lib/pebbles-uid/parse.rb
|
43
42
|
- lib/pebbles-uid/query.rb
|
44
43
|
- lib/pebbles-uid/version.rb
|
45
44
|
- lib/pebbles-uid/wildcard.rb
|