vedeu 0.0.38 → 0.0.39
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/deps.md +24 -11
- data/lib/vedeu/input/input.rb +2 -2
- data/lib/vedeu/launcher.rb +2 -0
- data/lib/vedeu/models/builders/builder.rb +41 -0
- data/lib/vedeu/models/builders/command_builder.rb +4 -25
- data/lib/vedeu/models/builders/interface_builder.rb +6 -26
- data/lib/vedeu/models/interface.rb +2 -2
- data/lib/vedeu/output/clear_interface.rb +10 -2
- data/lib/vedeu/parsing/text_adaptor.rb +7 -3
- data/lib/vedeu/repository/command_repository.rb +6 -6
- data/lib/vedeu/repository/interface_repository.rb +2 -18
- data/lib/vedeu/repository/repository.rb +25 -9
- data/lib/vedeu/repository/storage.rb +15 -20
- data/lib/vedeu/support/events.rb +58 -0
- data/lib/vedeu/support/exit.rb +2 -2
- data/lib/vedeu/support/{coordinate.rb → geometry.rb} +1 -1
- data/lib/vedeu/support/menu.rb +34 -6
- data/lib/vedeu/support/terminal.rb +1 -1
- data/lib/vedeu/support/translator.rb +2 -1
- data/lib/vedeu.rb +21 -7
- data/test/lib/vedeu/models/builders/builder_test.rb +11 -0
- data/test/lib/vedeu/models/interface_test.rb +3 -3
- data/test/lib/vedeu/parsing/text_adaptor_test.rb +24 -0
- data/test/lib/vedeu/repository/command_repository_test.rb +3 -11
- data/test/lib/vedeu/repository/interface_repository_test.rb +0 -23
- data/test/lib/vedeu/repository/repository_test.rb +45 -22
- data/test/lib/vedeu/repository/storage_test.rb +44 -19
- data/test/lib/vedeu/support/compositor_test.rb +2 -2
- data/test/lib/vedeu/support/events_test.rb +28 -0
- data/test/lib/vedeu/support/{coordinate_test.rb → geometry_test.rb} +110 -110
- data/test/lib/vedeu/support/menu_test.rb +69 -31
- data/vedeu.gemspec +1 -1
- metadata +11 -8
- data/lib/vedeu/repository/event_repository.rb +0 -35
- data/test/lib/vedeu/repository/event_repository_test.rb +0 -31
data/lib/vedeu.rb
CHANGED
@@ -3,8 +3,9 @@ require 'logger'
|
|
3
3
|
|
4
4
|
require_relative 'vedeu/models/builders/command_builder'
|
5
5
|
require_relative 'vedeu/models/builders/interface_builder'
|
6
|
-
require_relative 'vedeu/
|
7
|
-
require_relative 'vedeu/support/
|
6
|
+
require_relative 'vedeu/support/events'
|
7
|
+
require_relative 'vedeu/support/geometry'
|
8
|
+
require_relative 'vedeu/support/menu'
|
8
9
|
require_relative 'vedeu/support/exit'
|
9
10
|
require_relative 'vedeu/launcher'
|
10
11
|
|
@@ -20,17 +21,27 @@ module Vedeu
|
|
20
21
|
end
|
21
22
|
|
22
23
|
def event(name, &block)
|
23
|
-
|
24
|
+
Vedeu.events.on(name, &block)
|
24
25
|
end
|
26
|
+
alias_method :on, :event
|
25
27
|
|
26
28
|
def run(name, *args)
|
27
|
-
|
29
|
+
Vedeu.events.trigger(name, *args)
|
28
30
|
end
|
31
|
+
alias_method :trigger, :run
|
32
|
+
end
|
29
33
|
|
30
|
-
|
34
|
+
def self.events
|
35
|
+
@events ||= Events.new do
|
36
|
+
on(:_exit_) { fail StopIteration }
|
37
|
+
on(:_log_) { |message| Vedeu.logger.debug(message) }
|
38
|
+
on(:_mode_switch_) { fail ModeSwitch }
|
31
39
|
|
32
|
-
|
33
|
-
|
40
|
+
on(:_keypress_) do |key|
|
41
|
+
trigger(:key, key)
|
42
|
+
trigger(:_log_, "key: #{key}")
|
43
|
+
trigger(:_mode_switch_) if key == :escape
|
44
|
+
end
|
34
45
|
end
|
35
46
|
end
|
36
47
|
|
@@ -65,9 +76,12 @@ module Vedeu
|
|
65
76
|
end
|
66
77
|
|
67
78
|
def self.included(receiver)
|
79
|
+
receiver.send :include, ClassMethods
|
68
80
|
receiver.extend(ClassMethods)
|
69
81
|
end
|
70
82
|
|
83
|
+
extend ClassMethods
|
84
|
+
|
71
85
|
private
|
72
86
|
|
73
87
|
def self.root_path
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require_relative '../../../../test_helper'
|
2
|
+
require_relative '../../../../../lib/vedeu/models/builders/builder'
|
3
|
+
|
4
|
+
module Vedeu
|
5
|
+
describe Builder do
|
6
|
+
it 'raises an exception if not subclassed' do
|
7
|
+
builder = Builder.new('builder_test')
|
8
|
+
proc { builder.repository }.must_raise(StandardError)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -76,18 +76,18 @@ module Vedeu
|
|
76
76
|
end
|
77
77
|
|
78
78
|
describe '#geometry' do
|
79
|
-
it 'delegates to the
|
79
|
+
it 'delegates to the Geometry class' do
|
80
80
|
interface = Interface.new({
|
81
81
|
name: '#geometry',
|
82
82
|
width: 5,
|
83
83
|
height: 5
|
84
84
|
})
|
85
|
-
interface.geometry.must_be_instance_of(
|
85
|
+
interface.geometry.must_be_instance_of(Geometry)
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
89
|
describe '#origin' do
|
90
|
-
it 'delegates to the
|
90
|
+
it 'delegates to the Geometry class to get the origin' do
|
91
91
|
interface = Interface.new({
|
92
92
|
name: '#origin',
|
93
93
|
width: 5,
|
@@ -44,6 +44,30 @@ module Vedeu
|
|
44
44
|
]
|
45
45
|
)
|
46
46
|
end
|
47
|
+
|
48
|
+
it 'handles collections of lines' do
|
49
|
+
text = ["Lorm ipsum door sit amet, consecteur ",
|
50
|
+
"adipscing elit. Curbitur gravda nisl ",
|
51
|
+
"sit amet sagitis digisim. Nibh, eget."]
|
52
|
+
TextAdaptor.adapt(text).size.must_equal(3)
|
53
|
+
TextAdaptor.adapt(text).must_equal(
|
54
|
+
[
|
55
|
+
{
|
56
|
+
streams: {
|
57
|
+
text: "Lorm ipsum door sit amet, consecteur "
|
58
|
+
}
|
59
|
+
}, {
|
60
|
+
streams: {
|
61
|
+
text: "adipscing elit. Curbitur gravda nisl "
|
62
|
+
}
|
63
|
+
}, {
|
64
|
+
streams: {
|
65
|
+
text: "sit amet sagitis digisim. Nibh, eget."
|
66
|
+
}
|
67
|
+
}
|
68
|
+
]
|
69
|
+
)
|
70
|
+
end
|
47
71
|
end
|
48
72
|
end
|
49
73
|
end
|
@@ -37,23 +37,15 @@ module Vedeu
|
|
37
37
|
command.name.wont_equal('banana')
|
38
38
|
end
|
39
39
|
|
40
|
-
it 'returns
|
41
|
-
|
42
|
-
command.must_be_instance_of(FalseClass)
|
40
|
+
it 'returns false when no command was found' do
|
41
|
+
CommandRepository.by_input('not_found').must_be_instance_of(FalseClass)
|
43
42
|
end
|
44
43
|
|
45
|
-
it 'returns
|
44
|
+
it 'returns false when there is no input' do
|
46
45
|
CommandRepository.by_input('').must_be_instance_of(FalseClass)
|
47
46
|
end
|
48
47
|
end
|
49
48
|
|
50
|
-
describe '.create' do
|
51
|
-
it 'returns a Command' do
|
52
|
-
command = CommandRepository.create({})
|
53
|
-
command.must_be_instance_of(Command)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
49
|
describe '.entity' do
|
58
50
|
it 'returns Command' do
|
59
51
|
CommandRepository.entity.must_equal(Command)
|
@@ -5,29 +5,6 @@ module Vedeu
|
|
5
5
|
describe InterfaceRepository do
|
6
6
|
before { InterfaceRepository.reset }
|
7
7
|
|
8
|
-
describe '.create' do
|
9
|
-
it 'returns an Interface' do
|
10
|
-
InterfaceRepository.create({
|
11
|
-
name: 'dummy',
|
12
|
-
width: 5,
|
13
|
-
height: 5
|
14
|
-
}).must_be_instance_of(Interface)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe '.find' do
|
19
|
-
it 'returns the interface if it exists' do
|
20
|
-
hydrogen = InterfaceRepository.create({ name: 'hydrogen' })
|
21
|
-
|
22
|
-
InterfaceRepository.find('hydrogen').must_equal(hydrogen)
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'raises an exception if it does not exist' do
|
26
|
-
proc { InterfaceRepository.find('helium') }
|
27
|
-
.must_raise(UndefinedInterface)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
8
|
describe '.update' do
|
32
9
|
it 'returns an Interface' do
|
33
10
|
InterfaceRepository.update('dummy', { name: 'dumber' })
|
@@ -3,55 +3,78 @@ require_relative '../../../../lib/vedeu/repository/repository'
|
|
3
3
|
|
4
4
|
module Vedeu
|
5
5
|
class Dummy
|
6
|
-
|
7
|
-
|
6
|
+
attr_reader :name
|
7
|
+
|
8
|
+
def initialize(attributes = {})
|
9
|
+
@name = attributes.fetch(:name, '')
|
8
10
|
end
|
9
11
|
end
|
10
12
|
|
11
|
-
|
13
|
+
module DummyRepository
|
12
14
|
extend Repository
|
15
|
+
extend self
|
13
16
|
|
14
|
-
def
|
17
|
+
def entity
|
15
18
|
Dummy
|
16
19
|
end
|
17
20
|
end
|
18
21
|
|
19
22
|
describe Repository do
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
+
before { DummyRepository.reset }
|
24
|
+
|
25
|
+
describe '#create' do
|
26
|
+
it 'returns a Dummy' do
|
27
|
+
DummyRepository.create({ name: 'dummy' })
|
28
|
+
.must_be_instance_of(Dummy)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'raises an exception if called directly' do
|
32
|
+
proc { Repository.create({ name: 'test' }) }
|
33
|
+
.must_raise(StandardError)
|
23
34
|
end
|
24
35
|
end
|
25
36
|
|
26
37
|
describe '#all' do
|
27
38
|
it 'returns all the stored items' do
|
28
|
-
DummyRepository.all.
|
39
|
+
DummyRepository.all.must_equal([])
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'raises an exception if called directly' do
|
43
|
+
proc { Repository.all }.must_raise(StandardError)
|
29
44
|
end
|
30
45
|
end
|
31
46
|
|
32
47
|
describe '#query' do
|
33
|
-
it '
|
34
|
-
dumb =
|
35
|
-
DummyRepository.
|
36
|
-
|
37
|
-
result = DummyRepository.query(Dummy, :name, 'dummy')
|
48
|
+
it 'finds an entity by attribute' do
|
49
|
+
dumb = DummyRepository.create({ name: 'dummy' })
|
50
|
+
result = DummyRepository.query(:name, 'dummy')
|
38
51
|
result.must_equal(dumb)
|
52
|
+
end
|
39
53
|
|
40
|
-
|
41
|
-
|
54
|
+
it 'raises an exception when the entity cannot be found' do
|
55
|
+
proc { DummyRepository.query(:name, 'dumber') }
|
56
|
+
.must_raise(EntityNotFound)
|
42
57
|
end
|
43
|
-
end
|
44
58
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
DummyRepository.create(dummy).must_be_instance_of(Dummy)
|
59
|
+
it 'raises an exception if called directly' do
|
60
|
+
proc { Repository.query(:name, 'test') }
|
61
|
+
.must_raise(StandardError)
|
49
62
|
end
|
50
63
|
end
|
51
64
|
|
52
65
|
describe '#reset' do
|
53
|
-
it '
|
54
|
-
DummyRepository.reset.
|
66
|
+
it 'removes all stored entities' do
|
67
|
+
DummyRepository.reset.must_equal({})
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'raises an exception if called directly' do
|
71
|
+
proc { Repository.reset }.must_raise(StandardError)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe '#entity' do
|
76
|
+
it 'raises an exception if called directly' do
|
77
|
+
proc { Repository.entity }.must_raise(StandardError)
|
55
78
|
end
|
56
79
|
end
|
57
80
|
end
|
@@ -3,42 +3,67 @@ require_relative '../../../support/dummy_command'
|
|
3
3
|
require_relative '../../../../lib/vedeu/repository/storage'
|
4
4
|
|
5
5
|
module Vedeu
|
6
|
+
class DummyRecord
|
7
|
+
attr_reader :name
|
8
|
+
|
9
|
+
def initialize(attributes = {})
|
10
|
+
@name = attributes.fetch(:name, '')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
6
14
|
describe Storage do
|
7
15
|
describe '#create' do
|
8
16
|
it 'returns the stored record' do
|
9
|
-
Storage.new
|
10
|
-
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
describe '#delete' do
|
15
|
-
it 'returns a NilClass' do
|
16
|
-
Storage.new.delete(DummyCommand.new)
|
17
|
-
.must_be_instance_of(NilClass)
|
17
|
+
storage = Storage.new
|
18
|
+
storage.create(DummyRecord, {})
|
19
|
+
.must_be_instance_of(DummyRecord)
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
21
23
|
describe '#reset' do
|
22
|
-
it '
|
23
|
-
Storage.new
|
24
|
+
it 'deletes all records for this entity' do
|
25
|
+
storage = Storage.new
|
26
|
+
storage.create(DummyRecord, { name: 'dumb' })
|
27
|
+
storage.create(DummyRecord, { name: 'dumber' })
|
28
|
+
storage.all(DummyRecord).size.must_equal(2)
|
29
|
+
|
30
|
+
storage.reset(DummyRecord).must_equal({})
|
24
31
|
end
|
25
32
|
end
|
26
33
|
|
27
34
|
describe '#all' do
|
28
|
-
it 'returns an
|
29
|
-
|
35
|
+
it 'returns all entity records if an entity is provided' do
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'returns all records if no entity provided' do
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
it 'returns an empty collection when no records were found' do
|
45
|
+
storage = Storage.new
|
46
|
+
storage.all(DummyRecord).must_equal([])
|
30
47
|
end
|
31
48
|
end
|
32
49
|
|
33
50
|
describe '#query' do
|
34
|
-
it 'returns the
|
35
|
-
|
51
|
+
it 'returns the record if found' do
|
52
|
+
storage = Storage.new
|
53
|
+
hydrogen = storage.create(DummyRecord, { name: 'hydrogen' })
|
54
|
+
|
55
|
+
storage.query(DummyRecord, :name, 'hydrogen')
|
56
|
+
.must_be_instance_of(DummyRecord)
|
57
|
+
storage.query(DummyRecord, :name, 'hydrogen')
|
58
|
+
.name.must_equal('hydrogen')
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'returns false if the record is not found' do
|
36
62
|
storage = Storage.new
|
37
|
-
hydrogen = storage.create(
|
63
|
+
hydrogen = storage.create(DummyRecord, { name: 'hydrogen' })
|
38
64
|
|
39
|
-
storage.query(
|
40
|
-
storage.query(
|
41
|
-
storage.query(Record, :name, 'hydrogen').must_equal(hydrogen)
|
65
|
+
storage.query(DummyRecord, :name, nil).must_equal(false)
|
66
|
+
storage.query(DummyRecord, :name, 'lithium').must_equal(false)
|
42
67
|
end
|
43
68
|
end
|
44
69
|
end
|
@@ -30,9 +30,9 @@ module Vedeu
|
|
30
30
|
}
|
31
31
|
|
32
32
|
Compositor.enqueue(attributes)
|
33
|
-
InterfaceRepository.
|
33
|
+
InterfaceRepository.query(:name, 'Compositor.enqueue_1').dequeue
|
34
34
|
.must_match(/bd459118e6175689e4394e242debc2ae/)
|
35
|
-
InterfaceRepository.
|
35
|
+
InterfaceRepository.query(:name, 'Compositor.enqueue_2').dequeue
|
36
36
|
.must_match(/837acb2cb2ea3ef359257851142a7830/)
|
37
37
|
end
|
38
38
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative '../../../test_helper'
|
2
|
+
require_relative '../../../../lib/vedeu/support/events'
|
3
|
+
|
4
|
+
module Vedeu
|
5
|
+
describe Events do
|
6
|
+
describe '#on' do
|
7
|
+
it 'returns an Array' do
|
8
|
+
events = Events.new
|
9
|
+
events.on(:some_event) { proc { |x| x } }
|
10
|
+
.must_be_instance_of(Array)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#trigger' do
|
15
|
+
it 'returns a collection containing the event when the event is pre-registered' do
|
16
|
+
events = Events.new do
|
17
|
+
on(:_exit_) { fail StopIteration }
|
18
|
+
end
|
19
|
+
proc { events.trigger(:_exit_) }.must_raise(StopIteration)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'returns an empty collection when the event has not been registered' do
|
23
|
+
events = Events.new
|
24
|
+
events.trigger(:_not_found_).must_be_empty
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|