uh-layout 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8356446f440275b330daab65258ae6401736b0e0
4
- data.tar.gz: 4d677edea7b0df77f165c172ed6b920d7ad5083d
3
+ metadata.gz: edf8a87089f0c32d03e6e00cbc1bc40a93c84011
4
+ data.tar.gz: a1d22d1bdb126e9a699e0ca2fe8c343e569ccc32
5
5
  SHA512:
6
- metadata.gz: 7916c175a188b94e57bf96b530ab7ed9172ffb9b5c38d2f637dbf1d0457579fb3a7572ba16ba447d7c614041b2f63dcb2da69089d602a5dd367391bffaff96c1
7
- data.tar.gz: 4d15bed975b4d4433d381fdceef276cd6afad3aaf54358871bfa4a2ce397dbc1decab23079458ba34957d49e5ac0bfaf926cd561796cc7e84128a37ee3fe35f4
6
+ metadata.gz: b0cd253e73d437556eea6d053607a4f10d04b7f82d2c9cf13a6d985f44b2f346464de146bdc8f261d26196367ff5411abd725761eca691444bee1482e6c18180
7
+ data.tar.gz: f39cab274b9a47ac3a26a71dd736432bab091b3f425b9781f5aaaeceacbb08b490b49ea99c049bc4c3e234a2094ea8ef9d0b98c0a6ebc68220d7159c18537aee
@@ -28,7 +28,11 @@ module Uh
28
28
 
29
29
  def <<(client)
30
30
  client.geo = @geo.dup
31
- @clients << client
31
+ if @clients.current
32
+ @clients.insert_after_current client
33
+ else
34
+ @clients << client
35
+ end
32
36
  self
33
37
  end
34
38
 
@@ -23,6 +23,11 @@ module Uh
23
23
  @current_index = @entries.index entry
24
24
  end
25
25
 
26
+ def insert_after_current(entry)
27
+ fail RuntimeError, 'no current entry' unless current
28
+ @entries.insert @current_index + 1, entry
29
+ end
30
+
26
31
  def remove(entry)
27
32
  fail ArgumentError, 'unknown entry' unless include? entry
28
33
  @entries.delete_at @entries.index entry
@@ -1,5 +1,5 @@
1
1
  module Uh
2
2
  class Layout
3
- VERSION = '0.1.4'
3
+ VERSION = '0.1.5'
4
4
  end
5
5
  end
data/lib/uh/layout.rb CHANGED
@@ -15,6 +15,7 @@ require 'uh/layout/tag'
15
15
  module Uh
16
16
  class Layout
17
17
  Error = Class.new(StandardError)
18
+ RuntimeError = Class.new(RuntimeError)
18
19
  ArgumentError = Class.new(Error)
19
20
 
20
21
  extend Forwardable
@@ -22,14 +22,21 @@ module Uh
22
22
  describe '#<<' do
23
23
  before { column << client }
24
24
 
25
- it 'assigns column geo copy to given client' do
26
- expect(client.geo).to eq(column.geo).and not_be column.geo
27
- end
28
-
29
25
  it 'adds given client' do
30
26
  expect(column.clients).to include client
31
27
  end
32
28
 
29
+ it 'adds given client after current one' do
30
+ column << other_client
31
+ column.current_client = client
32
+ column << new_client = build_client
33
+ expect(column.clients.to_a).to eq [client, new_client, other_client]
34
+ end
35
+
36
+ it 'assigns column geo copy to given client' do
37
+ expect(client.geo).to eq(column.geo).and not_be column.geo
38
+ end
39
+
33
40
  it 'returns self' do
34
41
  expect(column << client).to be column
35
42
  end
@@ -56,6 +56,22 @@ module Uh
56
56
  end
57
57
  end
58
58
 
59
+ describe '#insert_after_current' do
60
+ it 'inserts given entry after current one' do
61
+ container.insert_after_current :baz
62
+ expect(container.entries).to eq %i[foo baz bar]
63
+ end
64
+
65
+ context 'when container has no entry' do
66
+ let(:entries) { [] }
67
+
68
+ it 'raises a RuntimeError' do
69
+ expect { container.insert_after_current :foo }
70
+ .to raise_error Layout::RuntimeError
71
+ end
72
+ end
73
+ end
74
+
59
75
  describe '#remove' do
60
76
  let(:entries) { %i[foo bar baz] }
61
77
 
@@ -140,7 +156,7 @@ module Uh
140
156
 
141
157
  it 'swaps current entry with consecutive one in given direction' do
142
158
  container.set :next
143
- expect(container.to_a).to eq %i[bar foo baz]
159
+ expect(container.entries).to eq %i[bar foo baz]
144
160
  end
145
161
 
146
162
  it 'does not change current entry' do
@@ -150,7 +166,7 @@ module Uh
150
166
  context 'when direction is out of range' do
151
167
  it 'rotates the entries' do
152
168
  container.set :pred
153
- expect(container.to_a).to eq %i[bar baz foo]
169
+ expect(container.entries).to eq %i[bar baz foo]
154
170
  end
155
171
 
156
172
  it 'does not change current entry' do
@@ -162,7 +178,7 @@ module Uh
162
178
  describe '#swap' do
163
179
  it 'swaps entries matched by given indexes' do
164
180
  container.swap 0, 1
165
- expect(container.to_a).to eq %i[bar foo]
181
+ expect(container.entries).to eq %i[bar foo]
166
182
  end
167
183
  end
168
184
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uh-layout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thibault Jouan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-16 00:00:00.000000000 Z
11
+ date: 2015-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uh