vedeu 0.0.39 → 0.0.40

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +0 -30
  3. data/Rakefile +8 -9
  4. data/bin/log +13 -0
  5. data/deps.md +11 -95
  6. data/lib/vedeu.rb +14 -46
  7. data/lib/vedeu/application.rb +4 -8
  8. data/lib/vedeu/instrumentation.rb +111 -0
  9. data/lib/vedeu/launcher.rb +2 -2
  10. data/lib/vedeu/models/attributes/interface_collection.rb +2 -2
  11. data/lib/vedeu/models/attributes/line_collection.rb +2 -2
  12. data/lib/vedeu/models/attributes/stream_collection.rb +2 -2
  13. data/lib/vedeu/models/colour.rb +1 -1
  14. data/lib/vedeu/models/composition.rb +1 -1
  15. data/lib/vedeu/models/interface.rb +18 -10
  16. data/lib/vedeu/models/line.rb +3 -3
  17. data/lib/vedeu/models/presentation.rb +1 -1
  18. data/lib/vedeu/models/stream.rb +2 -2
  19. data/lib/vedeu/models/style.rb +1 -1
  20. data/lib/vedeu/output/render_interface.rb +1 -1
  21. data/lib/vedeu/{support → parsing}/compositor.rb +1 -1
  22. data/lib/vedeu/parsing/hash_parser.rb +1 -1
  23. data/lib/vedeu/parsing/parser.rb +6 -10
  24. data/lib/vedeu/{models/builders → support}/builder.rb +19 -9
  25. data/lib/vedeu/support/esc.rb +1 -1
  26. data/lib/vedeu/support/events.rb +15 -19
  27. data/lib/vedeu/support/geometry.rb +3 -3
  28. data/lib/vedeu/{input → support}/input.rb +6 -9
  29. data/lib/vedeu/support/menu.rb +3 -3
  30. data/lib/vedeu/support/persistence.rb +41 -0
  31. data/lib/vedeu/support/terminal.rb +1 -1
  32. data/test/example_app/lib/app.rb +85 -5
  33. data/test/lib/vedeu/application_test.rb +2 -2
  34. data/test/lib/vedeu/configuration_test.rb +2 -2
  35. data/test/lib/vedeu/launcher_test.rb +2 -2
  36. data/test/lib/vedeu/models/attributes/collection_test.rb +2 -2
  37. data/test/lib/vedeu/models/attributes/interface_collection_test.rb +4 -4
  38. data/test/lib/vedeu/models/attributes/line_collection_test.rb +3 -3
  39. data/test/lib/vedeu/models/attributes/stream_collection_test.rb +3 -3
  40. data/test/lib/vedeu/models/colour_test.rb +2 -2
  41. data/test/lib/vedeu/models/composition_test.rb +19 -19
  42. data/test/lib/vedeu/models/interface_test.rb +46 -34
  43. data/test/lib/vedeu/models/line_test.rb +2 -2
  44. data/test/lib/vedeu/models/presentation_test.rb +2 -2
  45. data/test/lib/vedeu/models/stream_test.rb +2 -2
  46. data/test/lib/vedeu/models/style_test.rb +31 -31
  47. data/test/lib/vedeu/output/clear_interface_test.rb +5 -5
  48. data/test/lib/vedeu/output/render_interface_test.rb +5 -6
  49. data/test/lib/vedeu/output/template.rb +2 -1
  50. data/test/lib/vedeu/{support → parsing}/compositor_test.rb +6 -4
  51. data/test/lib/vedeu/parsing/hash_parser_test.rb +2 -2
  52. data/test/lib/vedeu/parsing/json_parser_test.rb +2 -2
  53. data/test/lib/vedeu/parsing/parser_test.rb +6 -5
  54. data/test/lib/vedeu/parsing/text_adaptor_test.rb +2 -2
  55. data/test/lib/vedeu/{models/builders/interface_builder_test.rb → support/builder_test.rb} +10 -10
  56. data/test/lib/vedeu/support/esc_test.rb +2 -2
  57. data/test/lib/vedeu/support/events_test.rb +2 -2
  58. data/test/lib/vedeu/support/geometry_test.rb +2 -2
  59. data/test/lib/vedeu/{input → support}/input_test.rb +6 -7
  60. data/test/lib/vedeu/support/menu_test.rb +2 -2
  61. data/test/lib/vedeu/support/persistence_test.rb +55 -0
  62. data/test/lib/vedeu/support/queue_test.rb +2 -2
  63. data/test/lib/vedeu/support/terminal_test.rb +2 -2
  64. data/test/lib/vedeu/support/translator_test.rb +2 -2
  65. data/test/lib/vedeu/support/wordwrap_test.rb +2 -2
  66. data/test/lib/vedeu_test.rb +17 -2
  67. data/test/support/bench.rb +34 -0
  68. data/test/test_helper.rb +3 -11
  69. data/vedeu.gemspec +2 -2
  70. metadata +20 -44
  71. data/lib/vedeu/models/builders/command_builder.rb +0 -10
  72. data/lib/vedeu/models/builders/interface_builder.rb +0 -32
  73. data/lib/vedeu/models/command.rb +0 -23
  74. data/lib/vedeu/output/output.rb +0 -14
  75. data/lib/vedeu/process/process.rb +0 -51
  76. data/lib/vedeu/repository/command_repository.rb +0 -31
  77. data/lib/vedeu/repository/interface_repository.rb +0 -31
  78. data/lib/vedeu/repository/repository.rb +0 -41
  79. data/lib/vedeu/repository/storage.rb +0 -40
  80. data/lib/vedeu/support/exit.rb +0 -9
  81. data/test/lib/vedeu/models/builders/builder_test.rb +0 -11
  82. data/test/lib/vedeu/models/builders/command_builder_test.rb +0 -16
  83. data/test/lib/vedeu/models/command_test.rb +0 -40
  84. data/test/lib/vedeu/output/output_test.rb +0 -19
  85. data/test/lib/vedeu/process/process_test.rb +0 -71
  86. data/test/lib/vedeu/repository/command_repository_test.rb +0 -55
  87. data/test/lib/vedeu/repository/interface_repository_test.rb +0 -67
  88. data/test/lib/vedeu/repository/repository_test.rb +0 -81
  89. data/test/lib/vedeu/repository/storage_test.rb +0 -70
  90. data/test/lib/vedeu/support/exit_test.rb +0 -12
  91. data/test/support/dummy_command.rb +0 -9
@@ -1,31 +0,0 @@
1
- require_relative '../models/command'
2
- require_relative 'repository'
3
-
4
- module Vedeu
5
- module CommandRepository
6
- extend Repository
7
- extend self
8
-
9
- def by_input(input)
10
- by_keypress(input) || by_keyword(input)
11
- end
12
-
13
- def entity
14
- Command
15
- end
16
-
17
- private
18
-
19
- def by_keypress(input)
20
- query(:keypress, input)
21
- rescue EntityNotFound
22
- false
23
- end
24
-
25
- def by_keyword(input)
26
- query(:keyword, input)
27
- rescue EntityNotFound
28
- false
29
- end
30
- end
31
- end
@@ -1,31 +0,0 @@
1
- require_relative '../models/interface'
2
- require_relative 'repository'
3
-
4
- module Vedeu
5
- module InterfaceRepository
6
- extend Repository
7
- extend self
8
-
9
- def update(name, attributes = {})
10
- interface = query(:name, name)
11
- interface.attributes = attributes
12
- interface
13
- rescue EntityNotFound
14
- create(attributes)
15
- end
16
-
17
- def refresh
18
- by_layer.map { |interface| interface.refresh }.compact
19
- end
20
-
21
- def entity
22
- Interface
23
- end
24
-
25
- private
26
-
27
- def by_layer
28
- all.sort_by { |interface| interface.z }
29
- end
30
- end
31
- end
@@ -1,41 +0,0 @@
1
- require_relative 'storage'
2
-
3
- module Vedeu
4
- EntityNotFound = Class.new(StandardError)
5
-
6
- module Repository
7
- extend self
8
-
9
- def create(attributes)
10
- storage.create(entity, attributes)
11
- end
12
-
13
- def all
14
- storage.all(entity)
15
- end
16
-
17
- def query(attribute, value)
18
- if result = storage.query(entity, attribute, value)
19
- result
20
-
21
- else
22
- fail EntityNotFound, "#{entity.to_s} could not be found."
23
-
24
- end
25
- end
26
-
27
- def reset
28
- storage.reset(entity)
29
- end
30
-
31
- def entity
32
- fail StandardError, 'The extending module implements this.'
33
- end
34
-
35
- private
36
-
37
- def storage
38
- @storage ||= Storage.new
39
- end
40
- end
41
- end
@@ -1,40 +0,0 @@
1
- module Vedeu
2
- class Storage
3
- def initialize
4
- @store = {}
5
- end
6
-
7
- def create(entity, attributes)
8
- entities(entity)
9
- .store(attributes[:name], entity.new(attributes))
10
- end
11
-
12
- def all(entity = nil)
13
- return entities unless entity
14
-
15
- entities(entity).values
16
- end
17
-
18
- def query(entity, attribute, value)
19
- return false if value.nil? || value.empty?
20
-
21
- entities(entity).select do |name, result|
22
- return result if result.send(attribute) == value
23
- end
24
-
25
- false
26
- end
27
-
28
- def reset(entity)
29
- store[entity.to_s] = {}
30
- end
31
-
32
- private
33
-
34
- attr_reader :store
35
-
36
- def entities(entity)
37
- store[entity.to_s] ||= {}
38
- end
39
- end
40
- end
@@ -1,9 +0,0 @@
1
- require_relative '../../vedeu'
2
-
3
- module Vedeu
4
- class Exit
5
- def self.dispatch
6
- Vedeu.trigger(:_exit_)
7
- end
8
- end
9
- end
@@ -1,11 +0,0 @@
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
@@ -1,16 +0,0 @@
1
- require_relative '../../../../test_helper'
2
- require_relative '../../../../../lib/vedeu/models/builders/command_builder'
3
- require_relative '../../../../support/dummy_command'
4
-
5
- module Vedeu
6
- describe CommandBuilder do
7
- it 'creates and stores a new command' do
8
- command = CommandBuilder.build('dummy') do
9
- entity DummyCommand
10
- keyword 'dummy'
11
- keypress 'd'
12
- end
13
- command.must_be_instance_of(Command)
14
- end
15
- end
16
- end
@@ -1,40 +0,0 @@
1
- require_relative '../../../test_helper'
2
- require_relative '../../../support/dummy_command'
3
- require_relative '../../../../lib/vedeu/models/command'
4
-
5
- module Vedeu
6
- describe Command do
7
- it 'has a name attribute' do
8
- Command.new({ name: 'dummy' }).name.must_equal('dummy')
9
- end
10
-
11
- it 'has an entity attribute' do
12
- Command.new({ entity: DummyCommand }).entity
13
- .must_equal(DummyCommand)
14
- end
15
-
16
- it 'has a keypress attribute' do
17
- Command.new({ keypress: 'd' }).keypress.must_equal('d')
18
- end
19
-
20
- it 'has an keyword attribute' do
21
- Command.new({ keyword: 'dummy' }).keyword.must_equal('dummy')
22
- end
23
-
24
- it 'has an arguments attribute' do
25
- Command.new({ arguments: [] }).arguments.must_equal([])
26
- end
27
-
28
- describe '#execute' do
29
- it 'returns the result of execution' do
30
- Command.new({
31
- name: 'dummy',
32
- entity: DummyCommand,
33
- keyword: 'dummy',
34
- keypress: 'd',
35
- arguments: []
36
- }).execute(:dummy).must_equal(:dummy)
37
- end
38
- end
39
- end
40
- end
@@ -1,19 +0,0 @@
1
- require_relative '../../../test_helper'
2
- require_relative '../../../../lib/vedeu/output/output'
3
- require_relative '../../../../lib/vedeu/support/terminal'
4
-
5
- module Vedeu
6
- describe Output do
7
- describe '.render' do
8
- it 'returns an Array' do
9
- output = "\e[3;3H \e[3;3H" \
10
- "\e[3;3HSome text...\e[3;3H"
11
- InterfaceRepository.stub(:refresh, [output]) do
12
- Terminal.stub(:output, output) do
13
- Output.render.first.must_equal(output)
14
- end
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,71 +0,0 @@
1
- require_relative '../../../test_helper'
2
- require_relative '../../../../lib/vedeu/process/process'
3
- require_relative '../../../support/dummy_command'
4
- require_relative '../../../../lib/vedeu/repository/command_repository'
5
-
6
- module Vedeu
7
- class QuitCommand
8
- def self.dispatch
9
- :stop
10
- end
11
- end
12
-
13
- class TestCommand
14
- def self.dispatch
15
- {
16
- 'Process#evaluate' => 'TestCommand.dispatch'
17
- }
18
- end
19
- end
20
-
21
- class NoResultCommand
22
- def self.dispatch
23
- end
24
- end
25
-
26
- describe Process do
27
- describe '.evaluate' do
28
- before do
29
- CommandRepository.reset
30
- Queue.reset
31
- end
32
-
33
- it 'returns false when there is no input' do
34
- Process.evaluate.must_be_instance_of(FalseClass)
35
- end
36
-
37
- it 'raises an exception when the result is :stop' do
38
- CommandRepository.create({
39
- name: 'quit',
40
- entity: QuitCommand,
41
- keypress: 'q'
42
- })
43
- Queue.enqueue('q')
44
- proc { Process.evaluate }.must_raise(StopIteration)
45
- end
46
-
47
- it 'returns a collection of interfaces when there is a result' do
48
- CommandRepository.create({
49
- name: 'test',
50
- entity: TestCommand,
51
- keypress: 't'
52
- })
53
- Queue.enqueue('t')
54
- evaluation = Process.evaluate
55
-
56
- evaluation.must_be_instance_of(Array)
57
- evaluation.size.must_equal(1)
58
- end
59
-
60
- it 'returns a NilClass when there is no result' do
61
- CommandRepository.create({
62
- name: 'no_result',
63
- entity: NoResultCommand,
64
- keypress: 'n'
65
- })
66
- Queue.enqueue('n')
67
- Process.evaluate.must_be_instance_of(NilClass)
68
- end
69
- end
70
- end
71
- end
@@ -1,55 +0,0 @@
1
- require_relative '../../../test_helper'
2
- require_relative '../../../support/dummy_command'
3
- require_relative '../../../../lib/vedeu/repository/command_repository'
4
-
5
- module Vedeu
6
- describe CommandRepository do
7
- before do
8
- CommandRepository.create({
9
- name: 'apple',
10
- entity: DummyCommand,
11
- keypress: 'a',
12
- keyword: 'apple'
13
- })
14
- CommandRepository.create({
15
- name: 'banana',
16
- entity: DummyCommand,
17
- keypress: 'b',
18
- keyword: 'banana'
19
- })
20
- end
21
- after { CommandRepository.reset }
22
-
23
- describe '.by_input' do
24
- it 'returns the correct command when the command was found by keypress' do
25
- command = CommandRepository.by_input('b')
26
-
27
- command.name.must_equal('banana')
28
- command.name.wont_equal('apple')
29
- command.keypress.must_equal('b')
30
- end
31
-
32
- it 'returns the correct command when the command was found by keyword' do
33
- command = CommandRepository.by_input('apple')
34
-
35
- command.keypress.must_equal('a')
36
- command.keypress.wont_equal('b')
37
- command.name.wont_equal('banana')
38
- end
39
-
40
- it 'returns false when no command was found' do
41
- CommandRepository.by_input('not_found').must_be_instance_of(FalseClass)
42
- end
43
-
44
- it 'returns false when there is no input' do
45
- CommandRepository.by_input('').must_be_instance_of(FalseClass)
46
- end
47
- end
48
-
49
- describe '.entity' do
50
- it 'returns Command' do
51
- CommandRepository.entity.must_equal(Command)
52
- end
53
- end
54
- end
55
- end
@@ -1,67 +0,0 @@
1
- require_relative '../../../test_helper'
2
- require_relative '../../../../lib/vedeu/repository/interface_repository'
3
-
4
- module Vedeu
5
- describe InterfaceRepository do
6
- before { InterfaceRepository.reset }
7
-
8
- describe '.update' do
9
- it 'returns an Interface' do
10
- InterfaceRepository.update('dummy', { name: 'dumber' })
11
- .must_be_instance_of(Interface)
12
- end
13
-
14
- it 'updates and returns the existing interface when the interface exists' do
15
- InterfaceRepository.update('dummy', { name: 'dumber' }).name
16
- .must_equal('dumber')
17
- end
18
-
19
- it 'returns a new interface when the interface does not exist' do
20
- InterfaceRepository.update('dummy', { name: 'dumber' }).name
21
- .must_equal('dumber')
22
- end
23
- end
24
-
25
- describe '.refresh' do
26
- it 'returns an Array' do
27
- InterfaceRepository.refresh.must_be_instance_of(Array)
28
- end
29
-
30
- it 'returns the collection in order they should be drawn' do
31
- InterfaceRepository.create({
32
- name: '.refresh_1',
33
- width: 1,
34
- height: 1,
35
- z: 3,
36
- lines: 'alpha'
37
- }).enqueue
38
- InterfaceRepository.create({
39
- name: '.refresh_2',
40
- width: 1,
41
- height: 1,
42
- z: 1,
43
- lines: 'beta'
44
- }).enqueue
45
- InterfaceRepository.create({
46
- name: '.refresh_3',
47
- width: 1,
48
- height: 1,
49
- z: 2,
50
- lines: 'gamma'
51
- }).enqueue
52
-
53
- InterfaceRepository.refresh.must_equal([
54
- "\e[1;1H \e[1;1H\e[1;1Hbeta",
55
- "\e[1;1H \e[1;1H\e[1;1Hgamma",
56
- "\e[1;1H \e[1;1H\e[1;1Halpha"
57
- ])
58
- end
59
- end
60
-
61
- describe '.entity' do
62
- it 'returns Interface' do
63
- InterfaceRepository.entity.must_equal(Interface)
64
- end
65
- end
66
- end
67
- end