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
@@ -5,11 +5,12 @@ module Vedeu
5
5
  end
6
6
 
7
7
  def initialize(html_colour = '')
8
- @html_colour = html_colour || ''
8
+ @html_colour = html_colour
9
9
  end
10
10
 
11
11
  def translate
12
12
  return '' unless valid?
13
+
13
14
  [16, red, green, blue].inject(:+)
14
15
  end
15
16
 
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/repository/event_repository'
7
- require_relative 'vedeu/support/coordinate'
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
- EventRepository.register(name, &block)
24
+ Vedeu.events.on(name, &block)
24
25
  end
26
+ alias_method :on, :event
25
27
 
26
28
  def run(name, *args)
27
- EventRepository.trigger(name, *args)
29
+ Vedeu.events.trigger(name, *args)
28
30
  end
31
+ alias_method :trigger, :run
32
+ end
29
33
 
30
- private
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
- def stringify_symbols(value)
33
- value.is_a?(::Symbol) ? value.to_s : value
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 Coordinate class' do
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(Coordinate)
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 Coordinate class to get the origin' do
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 FalseClass when no command was found' do
41
- command = CommandRepository.by_input('not_found')
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 FalseClass when there is no input' do
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
- def name
7
- 'dummy'
6
+ attr_reader :name
7
+
8
+ def initialize(attributes = {})
9
+ @name = attributes.fetch(:name, '')
8
10
  end
9
11
  end
10
12
 
11
- class DummyRepository
13
+ module DummyRepository
12
14
  extend Repository
15
+ extend self
13
16
 
14
- def self.entity
17
+ def entity
15
18
  Dummy
16
19
  end
17
20
  end
18
21
 
19
22
  describe Repository do
20
- describe '#adaptor' do
21
- it 'returns a Storage' do
22
- DummyRepository.adaptor.must_be_instance_of(Storage)
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.must_be_instance_of(Array)
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 'delegates to the adaptor' do
34
- dumb = Dummy.new
35
- DummyRepository.create(dumb)
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
- result = DummyRepository.query(Dummy, :name, 'dumber')
41
- result.must_equal(false)
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
- describe '#create' do
46
- it 'returns a Dummy' do
47
- dummy = DummyRepository.create(Dummy.new)
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 'returns an Array' do
54
- DummyRepository.reset.must_be_instance_of(Array)
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.create(DummyCommand.new)
10
- .must_be_instance_of(DummyCommand)
11
- end
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 'returns an Array' do
23
- Storage.new.reset(nil).must_be_instance_of(Array)
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 Array' do
29
- Storage.new.all(nil).must_be_instance_of(Array)
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 item if found, otherwise false' do
35
- Record = Struct.new(:name)
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(Record.new('hydrogen'))
63
+ hydrogen = storage.create(DummyRecord, { name: 'hydrogen' })
38
64
 
39
- storage.query(Record, :name, nil).must_equal(false)
40
- storage.query(Record, :name, 'lithium').must_equal(false)
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.find('Compositor.enqueue_1').dequeue
33
+ InterfaceRepository.query(:name, 'Compositor.enqueue_1').dequeue
34
34
  .must_match(/bd459118e6175689e4394e242debc2ae/)
35
- InterfaceRepository.find('Compositor.enqueue_2').dequeue
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