pebbles-uid 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/pebbles-uid/conditions.rb +3 -2
- data/lib/pebbles-uid/labels.rb +3 -2
- data/lib/pebbles-uid/version.rb +1 -1
- data/spec/conditions_spec.rb +5 -0
- data/spec/labels_spec.rb +5 -0
- metadata +3 -3
@@ -7,10 +7,11 @@ module Pebbles
|
|
7
7
|
|
8
8
|
NO_MARKER = Class.new
|
9
9
|
|
10
|
-
attr_reader :values, :name, :suffix, :stop
|
10
|
+
attr_reader :values, :name, :suffix, :stop, :max_depth
|
11
11
|
|
12
12
|
def initialize(values, options = {})
|
13
13
|
@values = values
|
14
|
+
@max_depth = options[:max_depth]
|
14
15
|
@name = options.fetch(:name) { 'label' }
|
15
16
|
@suffix = options.fetch(:suffix) { nil }
|
16
17
|
@stop = options.fetch(:stop) { NO_MARKER }
|
@@ -60,7 +61,7 @@ module Pebbles
|
|
60
61
|
end
|
61
62
|
|
62
63
|
def use_stop_marker?
|
63
|
-
stop != NO_MARKER
|
64
|
+
stop != NO_MARKER && !(values.size == max_depth)
|
64
65
|
end
|
65
66
|
|
66
67
|
end
|
data/lib/pebbles-uid/labels.rb
CHANGED
@@ -4,7 +4,7 @@ module Pebbles
|
|
4
4
|
|
5
5
|
NO_MARKER = Class.new
|
6
6
|
|
7
|
-
attr_reader :values, :name, :suffix, :stop
|
7
|
+
attr_reader :values, :name, :suffix, :stop, :max_depth
|
8
8
|
def initialize(*values)
|
9
9
|
options = values.pop if values.last.is_a?(Hash)
|
10
10
|
options ||= {}
|
@@ -12,6 +12,7 @@ module Pebbles
|
|
12
12
|
@name = options[:name]
|
13
13
|
@suffix = options[:suffix]
|
14
14
|
@stop = options.fetch(:stop) { NO_MARKER }
|
15
|
+
@max_depth = options[:max_depth]
|
15
16
|
end
|
16
17
|
|
17
18
|
def first
|
@@ -69,7 +70,7 @@ module Pebbles
|
|
69
70
|
end
|
70
71
|
|
71
72
|
def use_stop_marker?
|
72
|
-
stop != NO_MARKER
|
73
|
+
stop != NO_MARKER && !(values.size == max_depth)
|
73
74
|
end
|
74
75
|
|
75
76
|
end
|
data/lib/pebbles-uid/version.rb
CHANGED
data/spec/conditions_spec.rb
CHANGED
@@ -16,6 +16,11 @@ describe Pebbles::Uid::Conditions do
|
|
16
16
|
its(:to_hash) { should eq(:label_0 => "x", :label_1 => "y", :label_2 => "z", :label_3 => nil) }
|
17
17
|
end
|
18
18
|
|
19
|
+
describe "stop label and max depth" do
|
20
|
+
subject { Pebbles::Uid::Conditions.new(%w(x y z), :stop => nil, :max_depth => 3) }
|
21
|
+
its(:to_hash) { should eq(:label_0 => "x", :label_1 => "y", :label_2 => "z") }
|
22
|
+
end
|
23
|
+
|
19
24
|
describe "next label" do
|
20
25
|
subject { Pebbles::Uid::Conditions.new(%w(h j k l), :name => 'vim') }
|
21
26
|
its(:next) { should eq(:vim_4) }
|
data/spec/labels_spec.rb
CHANGED
@@ -22,6 +22,11 @@ describe Pebbles::Uid::Labels do
|
|
22
22
|
uid.to_hash.should eq(:whatevs_0_hey => 'a', :whatevs_1_hey => 'b', :whatevs_2_hey => 'c')
|
23
23
|
end
|
24
24
|
|
25
|
+
it "handles max-depth" do
|
26
|
+
uid = Pebbles::Uid::Labels.new('a.b.c', :name => 'label', :stop => 'HALT', :max_depth => 3)
|
27
|
+
uid.to_hash.should eq(:label_0 => 'a', :label_1 => 'b', :label_2 => 'c')
|
28
|
+
end
|
29
|
+
|
25
30
|
describe "alternate constructors" do
|
26
31
|
it { Pebbles::Uid::Labels.new('a', 'b', 'c').to_s.should eq('a.b.c') }
|
27
32
|
it { Pebbles::Uid::Labels.new(['a', 'b', 'c']).to_s.should eq('a.b.c') }
|
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.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-10-15 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70312268457800 !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: *70312268457800
|
25
25
|
description: Handle pebble UIDs conveniently.
|
26
26
|
email:
|
27
27
|
- katrina.owen@gmail.com
|