vedeu 0.0.33 → 0.0.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vedeu/models/{collection.rb → attributes/collection.rb} +0 -0
  3. data/lib/vedeu/models/{interface_collection.rb → attributes/interface_collection.rb} +1 -1
  4. data/lib/vedeu/models/{line_collection.rb → attributes/line_collection.rb} +1 -1
  5. data/lib/vedeu/models/{stream_collection.rb → attributes/stream_collection.rb} +1 -1
  6. data/lib/vedeu/models/composition.rb +4 -23
  7. data/lib/vedeu/models/interface.rb +17 -17
  8. data/lib/vedeu/models/line.rb +6 -12
  9. data/lib/vedeu/models/stream.rb +5 -11
  10. data/lib/vedeu/output/interface_renderer.rb +4 -10
  11. data/lib/vedeu/repository/command_repository.rb +2 -2
  12. data/lib/vedeu/repository/interface_repository.rb +7 -3
  13. data/lib/vedeu/repository/repository.rb +0 -4
  14. data/lib/vedeu/repository/storage.rb +1 -5
  15. data/lib/vedeu/support/compositor.rb +25 -0
  16. data/lib/vedeu/support/coordinate.rb +41 -54
  17. data/lib/vedeu/support/parser.rb +2 -2
  18. data/test/lib/vedeu/models/{collection_test.rb → attributes/collection_test.rb} +2 -2
  19. data/test/lib/vedeu/models/{interface_collection_test.rb → attributes/interface_collection_test.rb} +3 -3
  20. data/test/lib/vedeu/models/{line_collection_test.rb → attributes/line_collection_test.rb} +3 -3
  21. data/test/lib/vedeu/models/{stream_collection_test.rb → attributes/stream_collection_test.rb} +3 -3
  22. data/test/lib/vedeu/models/composition_test.rb +45 -65
  23. data/test/lib/vedeu/models/interface_test.rb +84 -38
  24. data/test/lib/vedeu/models/line_test.rb +20 -14
  25. data/test/lib/vedeu/models/presentation_test.rb +10 -6
  26. data/test/lib/vedeu/output/interface_renderer_test.rb +4 -4
  27. data/test/lib/vedeu/process/process_test.rb +5 -2
  28. data/test/lib/vedeu/repository/interface_repository_test.rb +32 -20
  29. data/test/lib/vedeu/repository/repository_test.rb +9 -11
  30. data/test/lib/vedeu/repository/storage_test.rb +8 -9
  31. data/test/lib/vedeu/support/compositor_test.rb +40 -0
  32. data/test/lib/vedeu/support/coordinate_test.rb +0 -16
  33. data/test/lib/vedeu/support/parser_test.rb +7 -4
  34. data/test/test_helper.rb +2 -0
  35. data/vedeu.gemspec +1 -1
  36. metadata +17 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 73c1296c50c2e542fe744337b953c07e2a14ee03
4
- data.tar.gz: 55e5fa60d09ce7c65382a2ff664b79e717cb0228
3
+ metadata.gz: 2ea325bc6c7ebf8080510b64ab7529f2ed504b97
4
+ data.tar.gz: fe17337d4699b19d701442298095df4204a56c7f
5
5
  SHA512:
6
- metadata.gz: 8816692395970fdb8a2b9003a625348cef3255c23c9340b56bfdb0297efbedbdc63d53f903caba320f7d94eb0f9f7f1834f4a4a721785a7b0e7142b377124952
7
- data.tar.gz: 7f321725fa3838de38dfcfd1091dbbd66ee5bc6439d47322fc3075ebd249c6ca52218f21c83fa7edb091ad5562783083998df9b1d05d6e6ec45c8b64deec0183
6
+ metadata.gz: b9ce3531ba1d457e6f8f4b1ef8bd0d19211636edafba1dd2e6da80deaea6ef26404649df0dcb771ec6c74741b2aef312e1b9945bbe7542bac3229dd099f09641
7
+ data.tar.gz: ad41764646d32bb82b0603c53524663f2747719a4b9989aa0fa128bfeada4d2de3f87eb99b34de834e71d6d66d9e462017279357f2040c46d3aa7d68f5e22ca2
@@ -1,6 +1,6 @@
1
1
  require 'virtus'
2
2
 
3
- require_relative '../repository/interface_repository'
3
+ require_relative '../../repository/interface_repository'
4
4
 
5
5
  module Vedeu
6
6
  class InterfaceCollection < Virtus::Attribute
@@ -1,7 +1,7 @@
1
1
  require 'virtus'
2
2
 
3
3
  require_relative 'collection'
4
- require_relative 'line'
4
+ require_relative '../line'
5
5
 
6
6
  module Vedeu
7
7
  class LineCollection < Virtus::Attribute
@@ -1,7 +1,7 @@
1
1
  require 'virtus'
2
2
 
3
3
  require_relative 'collection'
4
- require_relative 'stream'
4
+ require_relative '../stream'
5
5
 
6
6
  module Vedeu
7
7
  class StreamCollection < Virtus::Attribute
@@ -1,7 +1,7 @@
1
1
  require 'json'
2
2
  require 'virtus'
3
3
 
4
- require_relative 'interface_collection'
4
+ require_relative 'attributes/interface_collection'
5
5
 
6
6
  module Vedeu
7
7
  class Composition
@@ -9,33 +9,14 @@ module Vedeu
9
9
 
10
10
  attribute :interfaces, InterfaceCollection
11
11
 
12
- def self.enqueue(composition)
13
- new(composition).enqueue
14
- end
15
-
16
- def enqueue
17
- interfaces.map do |interface|
18
- interface.enqueue(interface.to_s)
19
- interface
20
- end
21
-
22
- self
23
- end
24
-
25
12
  def to_json
26
- json_attributes.to_json
13
+ {
14
+ interfaces: interfaces
15
+ }.to_json
27
16
  end
28
17
 
29
18
  def to_s
30
19
  interfaces.map(&:to_s).join
31
20
  end
32
-
33
- private
34
-
35
- def json_attributes
36
- {
37
- interfaces: interfaces
38
- }
39
- end
40
21
  end
41
22
  end
@@ -2,7 +2,7 @@ require 'json'
2
2
  require 'virtus'
3
3
 
4
4
  require_relative 'presentation'
5
- require_relative 'line_collection'
5
+ require_relative 'attributes/line_collection'
6
6
  require_relative 'style'
7
7
  require_relative '../output/interface_renderer'
8
8
  require_relative '../support/coordinate'
@@ -28,6 +28,10 @@ module Vedeu
28
28
  attribute :cursor, Boolean, default: true
29
29
  attribute :centred, Boolean, default: false
30
30
 
31
+ def enqueue
32
+ super(self.to_s)
33
+ end
34
+
31
35
  def origin(index = 0)
32
36
  geometry.origin(index)
33
37
  end
@@ -46,7 +50,18 @@ module Vedeu
46
50
  end
47
51
 
48
52
  def to_json(*args)
49
- json_attributes.to_json
53
+ {
54
+ colour: colour,
55
+ style: style_original,
56
+ name: name,
57
+ lines: lines,
58
+ y: y,
59
+ x: x,
60
+ z: z,
61
+ width: width,
62
+ height: height,
63
+ cursor: cursor
64
+ }.to_json
50
65
  end
51
66
 
52
67
  def to_s
@@ -67,21 +82,6 @@ module Vedeu
67
82
  InterfaceRenderer.clear(self)
68
83
  end
69
84
 
70
- def json_attributes
71
- {
72
- colour: colour,
73
- style: style_original,
74
- name: name,
75
- lines: lines,
76
- y: y,
77
- x: x,
78
- z: z,
79
- width: width,
80
- height: height,
81
- cursor: cursor
82
- }
83
- end
84
-
85
85
  def geometry
86
86
  @_geometry ||= Coordinate.new(attributes)
87
87
  end
@@ -2,7 +2,7 @@ require 'json'
2
2
  require 'virtus'
3
3
 
4
4
  require_relative 'presentation'
5
- require_relative 'stream_collection'
5
+ require_relative 'attributes/stream_collection'
6
6
  require_relative 'style'
7
7
 
8
8
  module Vedeu
@@ -15,21 +15,15 @@ module Vedeu
15
15
  attribute :streams, StreamCollection
16
16
 
17
17
  def to_json
18
- json_attributes.to_json
19
- end
20
-
21
- def to_s
22
- [colour, style, streams].join
23
- end
24
-
25
- private
26
-
27
- def json_attributes
28
18
  {
29
19
  colour: colour,
30
20
  style: style_original,
31
21
  streams: streams
32
- }
22
+ }.to_json
23
+ end
24
+
25
+ def to_s
26
+ [colour, style, streams].join
33
27
  end
34
28
  end
35
29
  end
@@ -14,21 +14,15 @@ module Vedeu
14
14
  attribute :text, String, default: ''
15
15
 
16
16
  def to_json
17
- json_attributes.to_json
18
- end
19
-
20
- def to_s(options = {})
21
- [colour, style, text].join
22
- end
23
-
24
- private
25
-
26
- def json_attributes
27
17
  {
28
18
  colour: colour,
29
19
  style: style_original,
30
20
  text: text
31
- }
21
+ }.to_json
22
+ end
23
+
24
+ def to_s(options = {})
25
+ [colour, style, text].join
32
26
  end
33
27
  end
34
28
  end
@@ -38,23 +38,17 @@ module Vedeu
38
38
  end
39
39
 
40
40
  def clear_lines
41
- height.times.inject([]) { |line, index| line << clear_line(index) }.join
41
+ interface.height.times.inject([]) do |line, index|
42
+ line << clear_line(index)
43
+ end.join
42
44
  end
43
45
 
44
46
  def clear_line(index)
45
- origin(index) + (' ' * width) + origin(index)
47
+ origin(index) + (' ' * interface.width)
46
48
  end
47
49
 
48
50
  def origin(index)
49
51
  interface.origin(index)
50
52
  end
51
-
52
- def height
53
- interface.height
54
- end
55
-
56
- def width
57
- interface.width
58
- end
59
53
  end
60
54
  end
@@ -21,11 +21,11 @@ module Vedeu
21
21
  private
22
22
 
23
23
  def by_keypress(input)
24
- query(entity, :keypress, input) || false
24
+ query(entity, :keypress, input)
25
25
  end
26
26
 
27
27
  def by_keyword(input)
28
- query(entity, :keyword, input) || false
28
+ query(entity, :keyword, input)
29
29
  end
30
30
  end
31
31
  end
@@ -13,9 +13,13 @@ module Vedeu
13
13
  end
14
14
 
15
15
  def find(name)
16
- result = super
17
- fail UndefinedInterface, "#{name.to_s} could not be found." unless result
18
- result
16
+ if result = query(entity, :name, name)
17
+ result
18
+
19
+ else
20
+ fail UndefinedInterface, "#{name.to_s} could not be found."
21
+
22
+ end
19
23
  end
20
24
 
21
25
  def update(name, attributes = {})
@@ -6,10 +6,6 @@ module Vedeu
6
6
  @adaptor ||= Storage.new
7
7
  end
8
8
 
9
- def find(name)
10
- adaptor.find(entity, name)
11
- end
12
-
13
9
  def all
14
10
  adaptor.all(entity)
15
11
  end
@@ -16,10 +16,6 @@ module Vedeu
16
16
  all(entity).map { |record| delete(record) }
17
17
  end
18
18
 
19
- def find(entity, name)
20
- map_for_class(entity).fetch(name, nil)
21
- end
22
-
23
19
  def all(entity)
24
20
  map_for_class(entity).values
25
21
  end
@@ -31,7 +27,7 @@ module Vedeu
31
27
  return result if result.send(attribute) == value
32
28
  end
33
29
 
34
- nil
30
+ false
35
31
  end
36
32
 
37
33
  private
@@ -0,0 +1,25 @@
1
+ require_relative '../models/composition'
2
+
3
+ module Vedeu
4
+ class Compositor
5
+ def self.enqueue(attributes)
6
+ new(attributes).enqueue
7
+ end
8
+
9
+ def initialize(attributes)
10
+ @attributes = attributes
11
+ end
12
+
13
+ def enqueue
14
+ composition.interfaces.map { |interface| interface.enqueue }
15
+ end
16
+
17
+ private
18
+
19
+ attr_reader :attributes
20
+
21
+ def composition
22
+ @composition ||= Composition.new(attributes)
23
+ end
24
+ end
25
+ end
@@ -21,80 +21,55 @@ module Vedeu
21
21
  end
22
22
 
23
23
  def terminal_height
24
- fail OutOfBoundsError,
25
- 'Value must be greater than or equal to 1.' if @terminal_height < 1
24
+ fail_if_less_than_one(@terminal_height)
26
25
 
27
- if @terminal_height > Terminal.height
28
- fail OutOfBoundsError, 'Cannot set terminal_height to be ' \
29
- 'greater than the actual terminal ' \
30
- 'height.'
31
- else
32
- @terminal_height
33
- end
26
+ fail_if_out_of_bounds('terminal_height',
27
+ @terminal_height,
28
+ Terminal.height)
29
+
30
+ @terminal_height
34
31
  end
35
32
 
36
33
  def height
37
- fail OutOfBoundsError,
38
- 'Value must be greater than or equal to 1.' if @height < 1
34
+ fail_if_less_than_one(@height)
39
35
 
40
- if @height > terminal_height
41
- fail OutOfBoundsError, 'Cannot set height to be greater ' \
42
- 'than the specified or actual ' \
43
- 'terminal height.'
44
- else
45
- @height
46
- end
36
+ fail_if_out_of_bounds('height', @height, terminal_height)
37
+
38
+ @height
47
39
  end
48
40
 
49
41
  def y
50
- fail OutOfBoundsError,
51
- 'Value must be greater than or equal to 1.' if @y < 1
42
+ fail_if_less_than_one(@y)
52
43
 
53
- if @y > terminal_height
54
- fail OutOfBoundsError, 'Cannot set y position to be greater' \
55
- ' that the specified terminal height' \
56
- ' or actual terminal height.'
57
- else
58
- @y
59
- end
44
+ fail_if_out_of_bounds('y', @y, terminal_height)
45
+
46
+ @y
60
47
  end
61
48
 
62
49
  def terminal_width
63
- fail OutOfBoundsError,
64
- 'Value must be greater than or equal to 1.' if @terminal_width < 1
65
- if @terminal_width > Terminal.width
66
- fail OutOfBoundsError, 'Cannot set terminal_width to be ' \
67
- 'greater than the actual terminal ' \
68
- 'width.'
69
- else
70
- @terminal_width
71
- end
50
+ fail_if_less_than_one(@terminal_width)
51
+
52
+ fail_if_out_of_bounds('terminal_width',
53
+ @terminal_width,
54
+ Terminal.width)
55
+
56
+ @terminal_width
72
57
  end
73
58
 
74
59
  def width
75
- fail OutOfBoundsError,
76
- 'Value must be greater than or equal to 1.' if @width < 1
60
+ fail_if_less_than_one(@width)
77
61
 
78
- if @width > terminal_width
79
- fail OutOfBoundsError, 'Cannot set width to be greater ' \
80
- 'than the specified or actual ' \
81
- 'terminal width.'
82
- else
83
- @width
84
- end
62
+ fail_if_out_of_bounds('width', @width, terminal_width)
63
+
64
+ @width
85
65
  end
86
66
 
87
67
  def x
88
- fail OutOfBoundsError,
89
- 'Value must be greater than or equal to 1.' if @x < 1
68
+ fail_if_less_than_one(@x)
90
69
 
91
- if @x > terminal_width
92
- fail OutOfBoundsError, 'Cannot set x position to be greater' \
93
- ' that the specified terminal width' \
94
- ' or actual terminal width.'
95
- else
96
- @x
97
- end
70
+ fail_if_out_of_bounds('x', @x, terminal_width)
71
+
72
+ @x
98
73
  end
99
74
 
100
75
  def centred
@@ -151,6 +126,18 @@ module Vedeu
151
126
 
152
127
  private
153
128
 
129
+ def fail_if_less_than_one(value)
130
+ fail OutOfBoundsError,
131
+ 'Value must be greater than or equal to 1.' if value < 1
132
+ end
133
+
134
+ def fail_if_out_of_bounds(name, attribute, boundary)
135
+ if attribute > boundary
136
+ fail OutOfBoundsError,
137
+ "Cannot set #{name} to be outside the terminal visible area."
138
+ end
139
+ end
140
+
154
141
  def virtual_x
155
142
  left
156
143
  end
@@ -1,4 +1,4 @@
1
- require_relative '../models/composition'
1
+ require_relative 'compositor'
2
2
  require_relative 'parsing/hash_parser'
3
3
  require_relative 'parsing/json_parser'
4
4
 
@@ -17,7 +17,7 @@ module Vedeu
17
17
  def parse
18
18
  return nil if empty?
19
19
 
20
- Composition.enqueue(parsed_output)
20
+ Compositor.enqueue(parsed_output)
21
21
  end
22
22
 
23
23
  private
@@ -1,5 +1,5 @@
1
- require_relative '../../../test_helper'
2
- require_relative '../../../../lib/vedeu/models/collection'
1
+ require_relative '../../../../test_helper'
2
+ require_relative '../../../../../lib/vedeu/models/attributes/collection'
3
3
 
4
4
  module Vedeu
5
5
  class TestClass
@@ -1,6 +1,6 @@
1
- require_relative '../../../test_helper'
2
- require_relative '../../../../lib/vedeu/models/interface_collection'
3
- require_relative '../../../../lib/vedeu/models/composition'
1
+ require_relative '../../../../test_helper'
2
+ require_relative '../../../../../lib/vedeu/models/attributes/interface_collection'
3
+ require_relative '../../../../../lib/vedeu/models/composition'
4
4
 
5
5
  module Vedeu
6
6
  describe InterfaceCollection do
@@ -1,6 +1,6 @@
1
- require_relative '../../../test_helper'
2
- require_relative '../../../../lib/vedeu/models/line_collection'
3
- require_relative '../../../../lib/vedeu/models/interface'
1
+ require_relative '../../../../test_helper'
2
+ require_relative '../../../../../lib/vedeu/models/attributes/line_collection'
3
+ require_relative '../../../../../lib/vedeu/models/interface'
4
4
 
5
5
  module Vedeu
6
6
  describe LineCollection do
@@ -1,6 +1,6 @@
1
- require_relative '../../../test_helper'
2
- require_relative '../../../../lib/vedeu/models/stream_collection'
3
- require_relative '../../../../lib/vedeu/models/line'
1
+ require_relative '../../../../test_helper'
2
+ require_relative '../../../../../lib/vedeu/models/attributes/stream_collection'
3
+ require_relative '../../../../../lib/vedeu/models/line'
4
4
 
5
5
  module Vedeu
6
6
  describe StreamCollection do