vedeu 0.0.38 → 0.0.39

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/deps.md +24 -11
  3. data/lib/vedeu/input/input.rb +2 -2
  4. data/lib/vedeu/launcher.rb +2 -0
  5. data/lib/vedeu/models/builders/builder.rb +41 -0
  6. data/lib/vedeu/models/builders/command_builder.rb +4 -25
  7. data/lib/vedeu/models/builders/interface_builder.rb +6 -26
  8. data/lib/vedeu/models/interface.rb +2 -2
  9. data/lib/vedeu/output/clear_interface.rb +10 -2
  10. data/lib/vedeu/parsing/text_adaptor.rb +7 -3
  11. data/lib/vedeu/repository/command_repository.rb +6 -6
  12. data/lib/vedeu/repository/interface_repository.rb +2 -18
  13. data/lib/vedeu/repository/repository.rb +25 -9
  14. data/lib/vedeu/repository/storage.rb +15 -20
  15. data/lib/vedeu/support/events.rb +58 -0
  16. data/lib/vedeu/support/exit.rb +2 -2
  17. data/lib/vedeu/support/{coordinate.rb → geometry.rb} +1 -1
  18. data/lib/vedeu/support/menu.rb +34 -6
  19. data/lib/vedeu/support/terminal.rb +1 -1
  20. data/lib/vedeu/support/translator.rb +2 -1
  21. data/lib/vedeu.rb +21 -7
  22. data/test/lib/vedeu/models/builders/builder_test.rb +11 -0
  23. data/test/lib/vedeu/models/interface_test.rb +3 -3
  24. data/test/lib/vedeu/parsing/text_adaptor_test.rb +24 -0
  25. data/test/lib/vedeu/repository/command_repository_test.rb +3 -11
  26. data/test/lib/vedeu/repository/interface_repository_test.rb +0 -23
  27. data/test/lib/vedeu/repository/repository_test.rb +45 -22
  28. data/test/lib/vedeu/repository/storage_test.rb +44 -19
  29. data/test/lib/vedeu/support/compositor_test.rb +2 -2
  30. data/test/lib/vedeu/support/events_test.rb +28 -0
  31. data/test/lib/vedeu/support/{coordinate_test.rb → geometry_test.rb} +110 -110
  32. data/test/lib/vedeu/support/menu_test.rb +69 -31
  33. data/vedeu.gemspec +1 -1
  34. metadata +11 -8
  35. data/lib/vedeu/repository/event_repository.rb +0 -35
  36. data/test/lib/vedeu/repository/event_repository_test.rb +0 -31
@@ -6,6 +6,12 @@ module Vedeu
6
6
  let(:collection) { ['hydrogen', 'carbon', 'nitrogen', 'oxygen'] }
7
7
  let(:menu) { Menu.new(collection) }
8
8
 
9
+ describe '#events' do
10
+ it 'returns the events defined for menus' do
11
+ menu.events.must_be_instance_of(Array)
12
+ end
13
+ end
14
+
9
15
  describe '#current' do
10
16
  it 'returns the current index' do
11
17
  menu.current.must_equal(0)
@@ -18,7 +24,7 @@ module Vedeu
18
24
  end
19
25
 
20
26
  it 'returns the selected index when an item is selected' do
21
- menu.next.select
27
+ menu.next_item.select_item
22
28
  menu.selected.must_equal(1)
23
29
  end
24
30
  end
@@ -29,7 +35,7 @@ module Vedeu
29
35
  end
30
36
 
31
37
  it 'when the current item has changed, the tuple will change' do
32
- menu.next.next
38
+ menu.next_item.next_item
33
39
  menu.current_item.must_equal([2, 'nitrogen'])
34
40
  end
35
41
  end
@@ -40,7 +46,7 @@ module Vedeu
40
46
  end
41
47
 
42
48
  it 'returns a tuple containing the selected index and item' do
43
- menu.next.select
49
+ menu.next_item.select_item
44
50
  menu.selected_item.must_equal([1, 'carbon'])
45
51
  end
46
52
  end
@@ -58,7 +64,7 @@ module Vedeu
58
64
  end
59
65
 
60
66
  it 'returns a tuple when the current has changed' do
61
- menu.next.items.must_equal(
67
+ menu.next_item.items.must_equal(
62
68
  [
63
69
  [false, false, 'hydrogen'],
64
70
  [false, true, 'carbon'],
@@ -69,7 +75,7 @@ module Vedeu
69
75
  end
70
76
 
71
77
  it 'returns a tuple when an item is selected' do
72
- menu.next.select
78
+ menu.next_item.select_item
73
79
  menu.items.must_equal(
74
80
  [
75
81
  [false, false, 'hydrogen'],
@@ -82,8 +88,8 @@ module Vedeu
82
88
 
83
89
  it 'returns a tuple when the current has changed and an item ' \
84
90
  'is selected' do
85
- menu.next.select
86
- menu.next.next
91
+ menu.next_item.select_item
92
+ menu.next_item.next_item
87
93
  menu.items.must_equal(
88
94
  [
89
95
  [false, false, 'hydrogen'],
@@ -103,13 +109,13 @@ module Vedeu
103
109
  end
104
110
 
105
111
  it 'returns a tuple when the current has changed' do
106
- menu.next.render.must_equal(
112
+ menu.next_item.render.must_equal(
107
113
  [' hydrogen', ' > carbon', ' nitrogen', ' oxygen']
108
114
  )
109
115
  end
110
116
 
111
117
  it 'returns a tuple when an item is selected' do
112
- menu.next.select
118
+ menu.next_item.select_item
113
119
  menu.render.must_equal(
114
120
  [' hydrogen', '*> carbon', ' nitrogen', ' oxygen']
115
121
  )
@@ -117,73 +123,105 @@ module Vedeu
117
123
 
118
124
  it 'returns a tuple when the current has changed and an item ' \
119
125
  'is selected' do
120
- menu.next.select
121
- menu.next.next
126
+ menu.next_item.select_item
127
+ menu.next_item.next_item
122
128
  menu.render.must_equal(
123
129
  [' hydrogen', '* carbon', ' nitrogen', ' > oxygen']
124
130
  )
125
131
  end
126
132
  end
127
133
 
128
- describe '#top' do
134
+ describe '#top_item' do
129
135
  it 'sets current to the index of the first item' do
130
- menu.next
131
- menu.top.must_equal(0)
136
+ menu.next_item
137
+ menu.top_item.current.must_equal(0)
138
+ end
139
+
140
+ it 'returns the instance' do
141
+ menu.top_item.must_equal(menu)
142
+ end
143
+
144
+ it 'is chainable' do
145
+ menu.top_item.current.must_equal(0)
132
146
  end
133
147
  end
134
148
 
135
- describe '#bottom' do
149
+ describe '#bottom_item' do
136
150
  it 'sets current to the index of the last item' do
137
- menu.bottom.must_equal(3)
151
+ menu.bottom_item.current.must_equal(3)
152
+ end
153
+
154
+ it 'returns the instance' do
155
+ menu.top_item.must_equal(menu)
156
+ end
157
+
158
+ it 'is chainable' do
159
+ menu.bottom_item.current.must_equal(3)
138
160
  end
139
161
  end
140
162
 
141
- describe '#next' do
163
+ describe '#next_item' do
142
164
  it 'sets the current to the index of the next item' do
143
- menu.next.current.must_equal(1)
165
+ menu.next_item.current.must_equal(1)
144
166
  end
145
167
 
146
168
  it 'returns the instance' do
147
- menu.next.must_equal(menu)
169
+ menu.next_item.must_equal(menu)
148
170
  end
149
171
 
150
172
  it 'is chainable but does not loop' do
151
- menu.next.next.next.next.next.current.must_equal(3)
173
+ menu.next_item.next_item.next_item.next_item.next_item.current.must_equal(3)
152
174
  end
153
175
  end
154
176
 
155
- describe '#prev' do
177
+ describe '#prev_item' do
156
178
  it 'does not loop' do
157
- menu.prev.current.must_equal(0)
179
+ menu.prev_item.current.must_equal(0)
158
180
  end
159
181
 
160
182
  it 'sets the current to the index of the previous item' do
161
- menu.next.next.prev.current.must_equal(1)
183
+ menu.next_item.next_item.prev_item.current.must_equal(1)
162
184
  end
163
185
 
164
186
  it 'returns the instance' do
165
- menu.prev.must_equal(menu)
187
+ menu.prev_item.must_equal(menu)
166
188
  end
167
189
 
168
190
  it 'is chainable' do
169
- menu.next.next.next.prev.prev.current.must_equal(1)
191
+ menu.next_item.next_item.next_item.prev_item.prev_item.current.must_equal(1)
170
192
  end
171
193
  end
172
194
 
173
- describe '#select' do
195
+ describe '#select_item' do
174
196
  it 'sets the selected index to the current index' do
175
- menu.select.must_equal(0)
197
+ menu.select_item.selected.must_equal(0)
176
198
  end
177
199
 
178
200
  it 'sets the selected index to the current index' do
179
- menu.next.select.must_equal(1)
201
+ menu.next_item.select_item.selected.must_equal(1)
202
+ end
203
+
204
+ it 'returns the instance' do
205
+ menu.select_item.must_equal(menu)
206
+ end
207
+
208
+ it 'is chainable' do
209
+ menu.select_item.selected.must_equal(0)
180
210
  end
181
211
  end
182
212
 
183
- describe '#deselect' do
213
+ describe '#deselect_item' do
184
214
  it 'sets the selected index to nil' do
185
- menu.next.next.select
186
- menu.deselect.must_equal(nil)
215
+ menu.next_item.next_item.select_item
216
+ menu.deselect_item.selected.must_equal(nil)
217
+ end
218
+
219
+ it 'returns the instance' do
220
+ menu.deselect_item.must_equal(menu)
221
+ end
222
+
223
+ it 'is chainable' do
224
+ menu.deselect_item.selected.must_equal(nil)
187
225
  end
188
226
  end
189
227
 
data/vedeu.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'vedeu'
7
- spec.version = '0.0.38'
7
+ spec.version = '0.0.39'
8
8
  spec.authors = ['Gavin Laking']
9
9
  spec.email = ['gavinlaking@gmail.com']
10
10
  spec.summary = %q{A terminal case of wonderland.}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vedeu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.38
4
+ version: 0.0.39
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Laking
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-22 00:00:00.000000000 Z
11
+ date: 2014-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -177,6 +177,7 @@ files:
177
177
  - lib/vedeu/models/attributes/interface_collection.rb
178
178
  - lib/vedeu/models/attributes/line_collection.rb
179
179
  - lib/vedeu/models/attributes/stream_collection.rb
180
+ - lib/vedeu/models/builders/builder.rb
180
181
  - lib/vedeu/models/builders/command_builder.rb
181
182
  - lib/vedeu/models/builders/interface_builder.rb
182
183
  - lib/vedeu/models/colour.rb
@@ -197,14 +198,14 @@ files:
197
198
  - lib/vedeu/parsing/text_adaptor.rb
198
199
  - lib/vedeu/process/process.rb
199
200
  - lib/vedeu/repository/command_repository.rb
200
- - lib/vedeu/repository/event_repository.rb
201
201
  - lib/vedeu/repository/interface_repository.rb
202
202
  - lib/vedeu/repository/repository.rb
203
203
  - lib/vedeu/repository/storage.rb
204
204
  - lib/vedeu/support/compositor.rb
205
- - lib/vedeu/support/coordinate.rb
206
205
  - lib/vedeu/support/esc.rb
206
+ - lib/vedeu/support/events.rb
207
207
  - lib/vedeu/support/exit.rb
208
+ - lib/vedeu/support/geometry.rb
208
209
  - lib/vedeu/support/menu.rb
209
210
  - lib/vedeu/support/queue.rb
210
211
  - lib/vedeu/support/terminal.rb
@@ -221,6 +222,7 @@ files:
221
222
  - test/lib/vedeu/models/attributes/interface_collection_test.rb
222
223
  - test/lib/vedeu/models/attributes/line_collection_test.rb
223
224
  - test/lib/vedeu/models/attributes/stream_collection_test.rb
225
+ - test/lib/vedeu/models/builders/builder_test.rb
224
226
  - test/lib/vedeu/models/builders/command_builder_test.rb
225
227
  - test/lib/vedeu/models/builders/interface_builder_test.rb
226
228
  - test/lib/vedeu/models/colour_test.rb
@@ -241,14 +243,14 @@ files:
241
243
  - test/lib/vedeu/parsing/text_adaptor_test.rb
242
244
  - test/lib/vedeu/process/process_test.rb
243
245
  - test/lib/vedeu/repository/command_repository_test.rb
244
- - test/lib/vedeu/repository/event_repository_test.rb
245
246
  - test/lib/vedeu/repository/interface_repository_test.rb
246
247
  - test/lib/vedeu/repository/repository_test.rb
247
248
  - test/lib/vedeu/repository/storage_test.rb
248
249
  - test/lib/vedeu/support/compositor_test.rb
249
- - test/lib/vedeu/support/coordinate_test.rb
250
250
  - test/lib/vedeu/support/esc_test.rb
251
+ - test/lib/vedeu/support/events_test.rb
251
252
  - test/lib/vedeu/support/exit_test.rb
253
+ - test/lib/vedeu/support/geometry_test.rb
252
254
  - test/lib/vedeu/support/menu_test.rb
253
255
  - test/lib/vedeu/support/queue_test.rb
254
256
  - test/lib/vedeu/support/terminal_test.rb
@@ -307,6 +309,7 @@ test_files:
307
309
  - test/lib/vedeu/models/attributes/interface_collection_test.rb
308
310
  - test/lib/vedeu/models/attributes/line_collection_test.rb
309
311
  - test/lib/vedeu/models/attributes/stream_collection_test.rb
312
+ - test/lib/vedeu/models/builders/builder_test.rb
310
313
  - test/lib/vedeu/models/builders/command_builder_test.rb
311
314
  - test/lib/vedeu/models/builders/interface_builder_test.rb
312
315
  - test/lib/vedeu/models/colour_test.rb
@@ -327,14 +330,14 @@ test_files:
327
330
  - test/lib/vedeu/parsing/text_adaptor_test.rb
328
331
  - test/lib/vedeu/process/process_test.rb
329
332
  - test/lib/vedeu/repository/command_repository_test.rb
330
- - test/lib/vedeu/repository/event_repository_test.rb
331
333
  - test/lib/vedeu/repository/interface_repository_test.rb
332
334
  - test/lib/vedeu/repository/repository_test.rb
333
335
  - test/lib/vedeu/repository/storage_test.rb
334
336
  - test/lib/vedeu/support/compositor_test.rb
335
- - test/lib/vedeu/support/coordinate_test.rb
336
337
  - test/lib/vedeu/support/esc_test.rb
338
+ - test/lib/vedeu/support/events_test.rb
337
339
  - test/lib/vedeu/support/exit_test.rb
340
+ - test/lib/vedeu/support/geometry_test.rb
338
341
  - test/lib/vedeu/support/menu_test.rb
339
342
  - test/lib/vedeu/support/queue_test.rb
340
343
  - test/lib/vedeu/support/terminal_test.rb
@@ -1,35 +0,0 @@
1
- module Vedeu
2
- module EventRepository
3
- extend self
4
-
5
- def handlers
6
- @handlers ||= Hash.new { |h, k| h[k] = [] }.merge(defaults)
7
- end
8
-
9
- def register(event, &block)
10
- handlers[event] << block
11
- end
12
-
13
- def trigger(event, *args)
14
- handlers[event].each do |handler|
15
- handler.call(*args)
16
- end
17
- end
18
-
19
- private
20
-
21
- def defaults
22
- {
23
- :_exit_ => [ proc { fail StopIteration } ],
24
- :_keypress_ => [ proc { |key| keypress(key) } ],
25
- :_mode_switch_ => [ proc { fail ModeSwitch } ],
26
- }
27
- end
28
-
29
- def keypress(key)
30
- trigger(:key, key)
31
-
32
- trigger(:_mode_switch_) if key == :escape
33
- end
34
- end
35
- end
@@ -1,31 +0,0 @@
1
- require_relative '../../../test_helper'
2
- require_relative '../../../../lib/vedeu/repository/event_repository'
3
-
4
- module Vedeu
5
- describe EventRepository do
6
- describe '#handlers' do
7
- it 'returns a Hash' do
8
- EventRepository.handlers.must_be_instance_of(Hash)
9
- end
10
- end
11
-
12
- describe '#register' do
13
- it 'returns an Array' do
14
- EventRepository.register(:some_event) { proc { |x| x } }
15
- .must_be_instance_of(Array)
16
- end
17
- end
18
-
19
- describe '#trigger' do
20
- it 'returns a collection containing the event when the event is pre-registered' do
21
- EventRepository.register(:some_event) { proc { |x| x } }
22
- proc { EventRepository.trigger(:_exit_, []).first.call }
23
- .must_raise(StopIteration)
24
- end
25
-
26
- it 'returns an empty collection when the event has not been registered' do
27
- EventRepository.trigger(:_not_found_, []).must_be_empty
28
- end
29
- end
30
- end
31
- end