pebbles-uid 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/lib/pebbles-uid.rb CHANGED
@@ -18,6 +18,20 @@ module Pebbles
18
18
  [genus, path, oid.empty? ? nil : oid]
19
19
  end
20
20
 
21
+ def copy(uid, replacements = {})
22
+ _genus, _path, _oid = parse(uid)
23
+ genus = replacements.fetch(:genus) { _genus }
24
+ path = replacements.fetch(:path) { _path }
25
+ oid = replacements.fetch(:oid) { _oid }
26
+ new build(genus, path, oid)
27
+ end
28
+
29
+ def build(genus, path, oid)
30
+ s = "#{genus}:#{path}"
31
+ s << "$#{oid}" if oid
32
+ s
33
+ end
34
+
21
35
  def query(s, options = {})
22
36
  Pebbles::Uid::Query.new(s, options)
23
37
  end
@@ -109,9 +123,7 @@ module Pebbles
109
123
  end
110
124
 
111
125
  def to_s
112
- s = "#{genus}:#{path}"
113
- s << "$#{oid}" if oid
114
- s
126
+ Pebbles::Uid.build genus, path, oid
115
127
  end
116
128
 
117
129
  def parsed
@@ -1,5 +1,5 @@
1
1
  module Pebbles
2
2
  class Uid
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
data/spec/uid_spec.rb CHANGED
@@ -30,6 +30,20 @@ describe Pebbles::Uid do
30
30
  end
31
31
  end
32
32
 
33
+ context "when cloning" do
34
+ it "replaces genus" do
35
+ Pebbles::Uid.copy('post:a.b.c$123', :genus => 'page').to_s.should == 'page:a.b.c$123'
36
+ end
37
+
38
+ it "replaces path" do
39
+ Pebbles::Uid.copy('post:a.b.c$123', :path => 'x.y.z').to_s.should == 'post:x.y.z$123'
40
+ end
41
+
42
+ it "replaces oid" do
43
+ Pebbles::Uid.copy('post:a.b.c$123', :oid => 'xyz').to_s.should == 'post:a.b.c$xyz'
44
+ end
45
+ end
46
+
33
47
  describe "must" do
34
48
  specify "have a genus" do
35
49
  ->{ Pebbles::Uid.new(':tourism.norway$1') }.should raise_error(ArgumentError)
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.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-15 00:00:00.000000000 Z
12
+ date: 2012-10-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70093695987640 !ruby/object:Gem::Requirement
16
+ requirement: &70107839407440 !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: *70093695987640
24
+ version_requirements: *70107839407440
25
25
  description: Handle pebble UIDs conveniently.
26
26
  email:
27
27
  - katrina.owen@gmail.com