vedeu 0.4.13 → 0.4.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (251) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -1
  3. data/.travis.yml +2 -1
  4. data/Guardfile +6 -5
  5. data/README.md +3 -30
  6. data/Rakefile +5 -5
  7. data/bin/vedeu_drb_client +1 -1
  8. data/bin/vedeu_drb_server +91 -89
  9. data/bin/vedeu_test +4 -0
  10. data/config/rubocop_enabled.yml +5 -10
  11. data/examples/borders_app.rb +2 -1
  12. data/examples/colours_app.rb +13 -8
  13. data/examples/configuration_app.rb +3 -2
  14. data/examples/cursor_app.rb +16 -11
  15. data/examples/drb_app.rb +88 -89
  16. data/examples/focus_app.rb +31 -32
  17. data/examples/geometry_app.rb +2 -1
  18. data/examples/hello_world.rb +2 -1
  19. data/examples/lines_app.rb +2 -1
  20. data/examples/material_colours_app.rb +126 -0
  21. data/examples/typed_commands/typed_commands_app.rb +5 -1
  22. data/examples/view_templates_app/view_templates_app.rb +6 -3
  23. data/lib/vedeu/all.rb +1 -1
  24. data/lib/vedeu/api.rb +18 -10
  25. data/lib/vedeu/application.rb +0 -1
  26. data/lib/vedeu/bindings.rb +77 -16
  27. data/lib/vedeu/buffers/all.rb +2 -5
  28. data/lib/vedeu/buffers/buffer.rb +69 -25
  29. data/lib/vedeu/buffers/display_buffer.rb +3 -7
  30. data/lib/vedeu/configuration/all.rb +3 -6
  31. data/lib/vedeu/configuration/api.rb +28 -4
  32. data/lib/vedeu/configuration/cli.rb +9 -9
  33. data/lib/vedeu/configuration/configuration.rb +11 -7
  34. data/lib/vedeu/cursor/all.rb +3 -6
  35. data/lib/vedeu/cursor/cursor.rb +22 -14
  36. data/lib/vedeu/cursor/move.rb +32 -22
  37. data/lib/vedeu/cursor/refresh_cursor.rb +1 -1
  38. data/lib/vedeu/debug.rb +2 -1
  39. data/lib/vedeu/distributed/client.rb +1 -7
  40. data/lib/vedeu/distributed/server.rb +0 -4
  41. data/lib/vedeu/distributed/subprocess.rb +1 -1
  42. data/lib/vedeu/distributed/templates/default_configuration.vedeu +1 -1
  43. data/lib/vedeu/distributed/test_application.rb +3 -5
  44. data/lib/vedeu/distributed/uri.rb +2 -2
  45. data/lib/vedeu/dsl/all.rb +6 -6
  46. data/lib/vedeu/dsl/components/all.rb +0 -3
  47. data/lib/vedeu/dsl/components/border.rb +20 -12
  48. data/lib/vedeu/dsl/components/geometry.rb +68 -3
  49. data/lib/vedeu/dsl/components/keymap.rb +1 -2
  50. data/lib/vedeu/dsl/composition.rb +8 -1
  51. data/lib/vedeu/dsl/interface.rb +61 -11
  52. data/lib/vedeu/dsl/line.rb +12 -12
  53. data/lib/vedeu/dsl/shared/all.rb +4 -7
  54. data/lib/vedeu/dsl/shared/colour.rb +2 -2
  55. data/lib/vedeu/dsl/shared/text.rb +2 -35
  56. data/lib/vedeu/dsl/shared/use.rb +2 -2
  57. data/lib/vedeu/dsl/view.rb +4 -4
  58. data/lib/vedeu/events/all.rb +3 -5
  59. data/lib/vedeu/events/event.rb +5 -5
  60. data/lib/vedeu/geometry/all.rb +11 -16
  61. data/lib/vedeu/geometry/area.rb +2 -5
  62. data/lib/vedeu/geometry/canvas.rb +12 -16
  63. data/lib/vedeu/geometry/dimension.rb +20 -22
  64. data/lib/vedeu/geometry/geometry.rb +28 -30
  65. data/lib/vedeu/geometry/grid.rb +1 -1
  66. data/lib/vedeu/geometry/index_position.rb +7 -0
  67. data/lib/vedeu/geometry/null_geometry.rb +61 -0
  68. data/lib/vedeu/geometry/position.rb +0 -3
  69. data/lib/vedeu/geometry/position_index.rb +7 -0
  70. data/lib/vedeu/geometry/position_validator.rb +44 -33
  71. data/lib/vedeu/input/all.rb +5 -4
  72. data/lib/vedeu/input/keymap.rb +0 -1
  73. data/lib/vedeu/input/mapper.rb +1 -3
  74. data/lib/vedeu/launcher.rb +6 -7
  75. data/lib/vedeu/main_loop.rb +1 -2
  76. data/lib/vedeu/models/all.rb +1 -0
  77. data/lib/vedeu/models/cell.rb +5 -8
  78. data/lib/vedeu/models/char.rb +50 -15
  79. data/lib/vedeu/models/composition.rb +8 -1
  80. data/lib/vedeu/models/focus.rb +4 -4
  81. data/lib/vedeu/models/group.rb +3 -3
  82. data/lib/vedeu/models/interface.rb +62 -46
  83. data/lib/vedeu/models/line.rb +1 -1
  84. data/lib/vedeu/models/null.rb +48 -0
  85. data/lib/vedeu/models/stream.rb +5 -5
  86. data/lib/vedeu/output/all.rb +20 -30
  87. data/lib/vedeu/output/border.rb +93 -40
  88. data/lib/vedeu/output/clear.rb +100 -15
  89. data/lib/vedeu/output/colour.rb +56 -12
  90. data/lib/vedeu/output/compressor.rb +59 -0
  91. data/lib/vedeu/output/html_char.rb +4 -2
  92. data/lib/vedeu/output/null_border.rb +16 -4
  93. data/lib/vedeu/output/output.rb +13 -21
  94. data/lib/vedeu/output/presentation.rb +28 -23
  95. data/lib/vedeu/output/refresh.rb +2 -2
  96. data/lib/vedeu/output/renderers/all.rb +80 -3
  97. data/lib/vedeu/output/renderers/file_renderer.rb +38 -2
  98. data/lib/vedeu/output/renderers/html_renderer.rb +6 -4
  99. data/lib/vedeu/output/renderers/json_renderer.rb +52 -0
  100. data/lib/vedeu/output/renderers/null_renderer.rb +14 -0
  101. data/lib/vedeu/output/renderers/terminal_renderer.rb +2 -12
  102. data/lib/vedeu/output/style.rb +33 -3
  103. data/lib/vedeu/output/text.rb +98 -1
  104. data/lib/vedeu/output/translator.rb +30 -7
  105. data/lib/vedeu/output/viewport.rb +43 -79
  106. data/lib/vedeu/output/wordwrap.rb +4 -4
  107. data/lib/vedeu/repositories/all.rb +22 -179
  108. data/lib/vedeu/repositories/collection.rb +11 -13
  109. data/lib/vedeu/repositories/collections/all.rb +8 -0
  110. data/lib/vedeu/repositories/collections/chars.rb +9 -0
  111. data/lib/vedeu/repositories/collections/events.rb +9 -0
  112. data/lib/vedeu/repositories/collections/interfaces.rb +9 -0
  113. data/lib/vedeu/repositories/collections/keys.rb +9 -0
  114. data/lib/vedeu/repositories/collections/lines.rb +9 -0
  115. data/lib/vedeu/repositories/collections/streams.rb +9 -0
  116. data/lib/vedeu/repositories/model.rb +7 -2
  117. data/lib/vedeu/repositories/repositories/all.rb +14 -0
  118. data/lib/vedeu/repositories/repositories/background_colours.rb +14 -0
  119. data/lib/vedeu/repositories/repositories/borders.rb +38 -0
  120. data/lib/vedeu/repositories/repositories/buffers.rb +36 -0
  121. data/lib/vedeu/repositories/repositories/colours.rb +63 -0
  122. data/lib/vedeu/repositories/repositories/cursors.rb +29 -0
  123. data/lib/vedeu/repositories/repositories/events_repository.rb +24 -0
  124. data/lib/vedeu/repositories/repositories/foreground_colours.rb +14 -0
  125. data/lib/vedeu/repositories/repositories/geometries.rb +37 -0
  126. data/lib/vedeu/repositories/repositories/groups.rb +24 -0
  127. data/lib/vedeu/repositories/repositories/interfaces_repository.rb +24 -0
  128. data/lib/vedeu/repositories/repositories/keymaps.rb +24 -0
  129. data/lib/vedeu/repositories/repositories/menus.rb +24 -0
  130. data/lib/vedeu/repositories/repository.rb +29 -47
  131. data/lib/vedeu/storage/all.rb +6 -0
  132. data/lib/vedeu/storage/associative_store.rb +47 -0
  133. data/lib/vedeu/storage/conveyor_store.rb +69 -0
  134. data/lib/vedeu/storage/fifo_store.rb +37 -0
  135. data/lib/vedeu/storage/store.rb +58 -0
  136. data/lib/vedeu/support/all.rb +5 -10
  137. data/lib/vedeu/support/common.rb +0 -8
  138. data/lib/vedeu/support/log.rb +13 -24
  139. data/lib/vedeu/support/template.rb +4 -1
  140. data/lib/vedeu/support/terminal.rb +10 -10
  141. data/lib/vedeu/support/trace.rb +15 -88
  142. data/lib/vedeu/support/visibility.rb +73 -0
  143. data/lib/vedeu.rb +37 -0
  144. data/test/lib/vedeu/api_test.rb +7 -3
  145. data/test/lib/vedeu/application_test.rb +9 -3
  146. data/test/lib/vedeu/bindings_test.rb +21 -0
  147. data/test/lib/vedeu/buffers/buffer_test.rb +110 -134
  148. data/test/lib/vedeu/buffers/display_buffer_test.rb +8 -0
  149. data/test/lib/vedeu/configuration/api_test.rb +5 -1
  150. data/test/lib/vedeu/configuration/configuration_test.rb +4 -6
  151. data/test/lib/vedeu/cursor/cursor_test.rb +25 -17
  152. data/test/lib/vedeu/cursor/move_test.rb +7 -7
  153. data/test/lib/vedeu/distributed/client_test.rb +1 -1
  154. data/test/lib/vedeu/distributed/subprocess_test.rb +3 -1
  155. data/test/lib/vedeu/distributed/uri_test.rb +5 -5
  156. data/test/lib/vedeu/dsl/components/geometry_test.rb +43 -0
  157. data/test/lib/vedeu/dsl/components/keymap_test.rb +1 -1
  158. data/test/lib/vedeu/dsl/composition_test.rb +6 -5
  159. data/test/lib/vedeu/dsl/interface_test.rb +81 -16
  160. data/test/lib/vedeu/dsl/shared/colour_test.rb +4 -4
  161. data/test/lib/vedeu/dsl/shared/text_test.rb +87 -9
  162. data/test/lib/vedeu/dsl/stream_test.rb +1 -1
  163. data/test/lib/vedeu/events/event_test.rb +3 -1
  164. data/test/lib/vedeu/events/trigger_test.rb +8 -4
  165. data/test/lib/vedeu/geometry/dimension_test.rb +1 -1
  166. data/test/lib/vedeu/geometry/geometry_test.rb +5 -3
  167. data/test/lib/vedeu/geometry/index_position_test.rb +30 -7
  168. data/test/lib/vedeu/geometry/null_geometry_test.rb +57 -0
  169. data/test/lib/vedeu/geometry/position_index_test.rb +14 -0
  170. data/test/lib/vedeu/geometry/position_validator_test.rb +17 -3
  171. data/test/lib/vedeu/input/keymap_test.rb +3 -1
  172. data/test/lib/vedeu/input/mapper_test.rb +8 -4
  173. data/test/lib/vedeu/launcher_test.rb +1 -1
  174. data/test/lib/vedeu/models/cell_test.rb +10 -8
  175. data/test/lib/vedeu/models/char_test.rb +52 -28
  176. data/test/lib/vedeu/models/composition_test.rb +26 -4
  177. data/test/lib/vedeu/models/group_test.rb +11 -5
  178. data/test/lib/vedeu/models/interface_test.rb +32 -19
  179. data/test/lib/vedeu/models/line_test.rb +21 -25
  180. data/test/lib/vedeu/models/menu_test.rb +10 -6
  181. data/test/lib/vedeu/models/null_test.rb +66 -0
  182. data/test/lib/vedeu/models/stream_test.rb +13 -10
  183. data/test/lib/vedeu/output/border_test.rb +29 -8
  184. data/test/lib/vedeu/output/clear_test.rb +23 -4
  185. data/test/lib/vedeu/output/colour_test.rb +20 -4
  186. data/test/lib/vedeu/output/compressor_test.rb +43 -0
  187. data/test/lib/vedeu/output/html_char_test.rb +29 -17
  188. data/test/lib/vedeu/output/null_border_test.rb +2 -1
  189. data/test/lib/vedeu/output/output_test.rb +20 -30
  190. data/test/lib/vedeu/output/presentation_test.rb +39 -16
  191. data/test/lib/vedeu/output/refresh_test.rb +14 -10
  192. data/test/lib/vedeu/output/renderers/all_test.rb +96 -0
  193. data/test/lib/vedeu/output/renderers/file_renderer_test.rb +1 -1
  194. data/test/lib/vedeu/output/renderers/html_renderer_test.rb +13 -9
  195. data/test/lib/vedeu/output/renderers/json_renderer_test.rb +52 -0
  196. data/test/lib/vedeu/output/renderers/null_renderer_test.rb +19 -0
  197. data/test/lib/vedeu/output/style_test.rb +41 -1
  198. data/test/lib/vedeu/output/text_test.rb +61 -10
  199. data/test/lib/vedeu/output/translator_test.rb +14 -0
  200. data/test/lib/vedeu/output/viewport_test.rb +22 -3
  201. data/test/lib/vedeu/output/virtual_terminal_test.rb +3 -3
  202. data/test/lib/vedeu/output/wordwrap_test.rb +58 -45
  203. data/test/lib/vedeu/repositories/collections/chars_test.rb +16 -0
  204. data/test/lib/vedeu/repositories/collections/events_test.rb +16 -0
  205. data/test/lib/vedeu/repositories/collections/interfaces_test.rb +16 -0
  206. data/test/lib/vedeu/repositories/collections/keys_test.rb +16 -0
  207. data/test/lib/vedeu/repositories/collections/lines_test.rb +16 -0
  208. data/test/lib/vedeu/repositories/collections/streams_test.rb +16 -0
  209. data/test/lib/vedeu/repositories/repositories/background_colours_test.rb +17 -0
  210. data/test/lib/vedeu/repositories/repositories/borders_test.rb +51 -0
  211. data/test/lib/vedeu/repositories/repositories/buffers_test.rb +52 -0
  212. data/test/lib/vedeu/repositories/repositories/colours_test.rb +16 -0
  213. data/test/lib/vedeu/repositories/repositories/cursors_test.rb +39 -0
  214. data/test/lib/vedeu/repositories/repositories/events_repository_test.rb +17 -0
  215. data/test/lib/vedeu/repositories/repositories/foreground_colours_test.rb +17 -0
  216. data/test/lib/vedeu/repositories/repositories/geometries_test.rb +42 -0
  217. data/test/lib/vedeu/repositories/repositories/groups_test.rb +17 -0
  218. data/test/lib/vedeu/repositories/repositories/interfaces_repositories_test.rb +17 -0
  219. data/test/lib/vedeu/repositories/repositories/keymaps_test.rb +17 -0
  220. data/test/lib/vedeu/repositories/repositories/menus_test.rb +17 -0
  221. data/test/lib/vedeu/repositories/repository_test.rb +16 -36
  222. data/test/lib/vedeu/storage/associative_store_test.rb +69 -0
  223. data/test/lib/vedeu/storage/conveyor_store_test.rb +135 -0
  224. data/test/lib/vedeu/storage/fifo_store_test.rb +47 -0
  225. data/test/lib/vedeu/storage/store_test.rb +123 -0
  226. data/test/lib/vedeu/support/common_test.rb +0 -9
  227. data/test/lib/vedeu/support/terminal_test.rb +78 -55
  228. data/test/lib/vedeu/support/visibility_test.rb +80 -0
  229. data/test/test_helper.rb +13 -11
  230. data/vedeu.gemspec +4 -3
  231. metadata +92 -32
  232. data/lib/vedeu/cursor/toggle.rb +0 -55
  233. data/lib/vedeu/exceptions.rb +0 -37
  234. data/lib/vedeu/geometry/centre.rb +0 -85
  235. data/lib/vedeu/geometry/content.rb +0 -70
  236. data/lib/vedeu/geometry/limit.rb +0 -58
  237. data/lib/vedeu/output/compositor.rb +0 -62
  238. data/lib/vedeu/repositories/collections.rb +0 -41
  239. data/lib/vedeu/support/coercions.rb +0 -60
  240. data/lib/vedeu/support/sentence.rb +0 -91
  241. data/lib/vedeu/support/visible.rb +0 -90
  242. data/test/lib/vedeu/cursor/toggle_test.rb +0 -63
  243. data/test/lib/vedeu/geometry/centre_test.rb +0 -58
  244. data/test/lib/vedeu/geometry/content_test.rb +0 -98
  245. data/test/lib/vedeu/geometry/limit_test.rb +0 -30
  246. data/test/lib/vedeu/output/compositor_test.rb +0 -48
  247. data/test/lib/vedeu/repositories/all_test.rb +0 -135
  248. data/test/lib/vedeu/repositories/collections_test.rb +0 -71
  249. data/test/lib/vedeu/support/coercions_test.rb +0 -84
  250. data/test/lib/vedeu/support/sentence_test.rb +0 -56
  251. data/test/lib/vedeu/support/visible_test.rb +0 -161
@@ -0,0 +1,36 @@
1
+ module Vedeu
2
+
3
+ # Allows the storing of view buffers.
4
+ #
5
+ class Buffers < Repository
6
+
7
+ # @return [Vedeu::Buffers]
8
+ def self.buffers
9
+ @buffers ||= reset!
10
+ end
11
+
12
+ # @return [Vedeu::Buffers]
13
+ def self.repository
14
+ Vedeu.buffers
15
+ end
16
+
17
+ # @return [Vedeu::Buffers]
18
+ def self.reset!
19
+ @buffers = Vedeu::Buffers.register_repository(Vedeu::Buffer)
20
+ end
21
+
22
+ # @param name [String] The name of buffer to clear.
23
+ # @return [void]
24
+ def clear(name)
25
+ find!(name).clear
26
+ end
27
+
28
+ # @param name [String] The name of buffer to render.
29
+ # @return [void]
30
+ def render(name)
31
+ find!(name).render
32
+ end
33
+
34
+ end # Buffers
35
+
36
+ end # Vedeu
@@ -0,0 +1,63 @@
1
+ module Vedeu
2
+
3
+ # Allows the storing of HTML/CSS colours and their respective escape
4
+ # sequences.
5
+ #
6
+ class Colours
7
+
8
+ # @!attribute [r] storage
9
+ # @return [Hash<String => String>]
10
+ attr_reader :storage
11
+
12
+ # Returns a new instance of Vedeu::Colours.
13
+ #
14
+ # @return [Vedeu::Colours]
15
+ def initialize
16
+ @storage = {}
17
+ end
18
+
19
+ # Registers a colour with respective escape sequence.
20
+ #
21
+ # @return [String]
22
+ def register(colour, escape_sequence)
23
+ storage.store(colour, escape_sequence)
24
+ end
25
+
26
+ # Returns a boolean indicating whether the colour has been registered.
27
+ #
28
+ # @return [Boolean]
29
+ def registered?(colour)
30
+ storage.key?(colour)
31
+ end
32
+
33
+ # Removes all stored colours.
34
+ #
35
+ # @return [Hash]
36
+ def reset!
37
+ storage.clear
38
+ end
39
+
40
+ # Retrieves a registered colour.
41
+ #
42
+ # @return [String]
43
+ def retrieve(colour)
44
+ storage.fetch(colour, '')
45
+ end
46
+
47
+ # Retrieves a registered colour, or registers the colour with its respective
48
+ # escape sequence.
49
+ #
50
+ # @return [String]
51
+ def retrieve_or_register(colour, escape_sequence)
52
+ if registered?(colour)
53
+ retrieve(colour)
54
+
55
+ else
56
+ register(colour, escape_sequence)
57
+
58
+ end
59
+ end
60
+
61
+ end # Colours
62
+
63
+ end # Vedeu
@@ -0,0 +1,29 @@
1
+ module Vedeu
2
+
3
+ # Allows the storing of each interface's cursor.
4
+ #
5
+ class Cursors < Repository
6
+
7
+ # @return [Vedeu::Cursors]
8
+ def self.cursors
9
+ @cursors ||= reset!
10
+ end
11
+
12
+ # @return [Vedeu::Cursor]
13
+ def self.cursor
14
+ cursors.current
15
+ end
16
+
17
+ # @return [Vedeu::Cursors]
18
+ def self.repository
19
+ Vedeu.cursors
20
+ end
21
+
22
+ # @return [Vedeu::Cursors]
23
+ def self.reset!
24
+ @cursors = Vedeu::Cursors.register_repository(Vedeu::Cursor)
25
+ end
26
+
27
+ end # Cursors
28
+
29
+ end # Vedeu
@@ -0,0 +1,24 @@
1
+ module Vedeu
2
+
3
+ # Allows the storing of events.
4
+ #
5
+ class EventsRepository < Repository
6
+
7
+ # @return [Vedeu::EventsRepository]
8
+ def self.events
9
+ @events ||= reset!
10
+ end
11
+
12
+ # @return [Vedeu::EventsRepository]
13
+ def self.repository
14
+ Vedeu.events
15
+ end
16
+
17
+ # @return [Vedeu::EventsRepository]
18
+ def self.reset!
19
+ @events = Vedeu::EventsRepository.new(Vedeu::Events)
20
+ end
21
+
22
+ end # EventsRepository
23
+
24
+ end # Vedeu
@@ -0,0 +1,14 @@
1
+ module Vedeu
2
+
3
+ # Store foreground colour escape sequences by HTML/CSS code.
4
+ #
5
+ class ForegroundColours < Colours
6
+
7
+ # @return [Vedeu::ForegroundColours]
8
+ def self.foreground_colours
9
+ @foreground_colours ||= new
10
+ end
11
+
12
+ end # ForegroundColours
13
+
14
+ end # Vedeu
@@ -0,0 +1,37 @@
1
+ module Vedeu
2
+
3
+ # Allows the storing of interface/view geometry independent of the interface
4
+ # instance.
5
+ #
6
+ class Geometries < Repository
7
+
8
+ # @return [Vedeu::Geometries]
9
+ def self.geometries
10
+ @geometries ||= reset!
11
+ end
12
+
13
+ # @return [Vedeu::Geometries]
14
+ def self.repository
15
+ Vedeu.geometries
16
+ end
17
+
18
+ # @return [Vedeu::Geometries]
19
+ def self.reset!
20
+ @geometries = Vedeu::Geometries.new(Vedeu::Geometry)
21
+ end
22
+
23
+ # @param name [String] The name of the stored geometry.
24
+ # @return [Vedeu::Geometry|Vedeu::NullGeometry]
25
+ def by_name(name)
26
+ if registered?(name)
27
+ find(name)
28
+
29
+ else
30
+ Vedeu::NullGeometry.new
31
+
32
+ end
33
+ end
34
+
35
+ end # Geometries
36
+
37
+ end # Vedeu
@@ -0,0 +1,24 @@
1
+ module Vedeu
2
+
3
+ # Allows the storing of view groups.
4
+ #
5
+ class Groups < Repository
6
+
7
+ # @return [Vedeu::Groups]
8
+ def self.groups
9
+ @groups ||= reset!
10
+ end
11
+
12
+ # @return [Vedeu::Groups]
13
+ def self.repository
14
+ Vedeu.groups
15
+ end
16
+
17
+ # @return [Vedeu::Groups]
18
+ def self.reset!
19
+ @groups = Vedeu::Groups.new(Vedeu::Group)
20
+ end
21
+
22
+ end # Groups
23
+
24
+ end # Vedeu
@@ -0,0 +1,24 @@
1
+ module Vedeu
2
+
3
+ # Allows the storing of interfaces and views.
4
+ #
5
+ class InterfacesRepository < Repository
6
+
7
+ # @return [Vedeu::InterfacesRepository]
8
+ def self.interfaces
9
+ @interfaces ||= reset!
10
+ end
11
+
12
+ # @return [Vedeu::InterfacesRepository]
13
+ def self.repository
14
+ Vedeu.interfaces
15
+ end
16
+
17
+ # @return [Vedeu::InterfacesRepository]
18
+ def self.reset!
19
+ @interfaces = Vedeu::InterfacesRepository.new(Vedeu::Interface)
20
+ end
21
+
22
+ end # InterfacesRepository
23
+
24
+ end # Vedeu
@@ -0,0 +1,24 @@
1
+ module Vedeu
2
+
3
+ # Allows the storing of keymaps.
4
+ #
5
+ class Keymaps < Repository
6
+
7
+ # @return [Vedeu::Keymaps]
8
+ def self.keymaps
9
+ @keymaps ||= reset!
10
+ end
11
+
12
+ # @return [Vedeu::Keymaps]
13
+ def self.repository
14
+ Vedeu.keymaps
15
+ end
16
+
17
+ # @return [Vedeu::Keymaps]
18
+ def self.reset!
19
+ @keymaps = Vedeu::Keymaps.new(Vedeu::Keymap)
20
+ end
21
+
22
+ end # Keymaps
23
+
24
+ end # Vedeu
@@ -0,0 +1,24 @@
1
+ module Vedeu
2
+
3
+ # Allows the storing of menus by name.
4
+ #
5
+ class Menus < Repository
6
+
7
+ # @return [Vedeu::Menus]
8
+ def self.menus
9
+ @menus ||= reset!
10
+ end
11
+
12
+ # @return [Vedeu::Menus]
13
+ def self.repository
14
+ Vedeu.menus
15
+ end
16
+
17
+ # @return [Vedeu::Menus]
18
+ def self.reset!
19
+ @menus = Vedeu::Menus.new(Vedeu::Menu)
20
+ end
21
+
22
+ end # Menus
23
+
24
+ end # Vedeu
@@ -1,5 +1,5 @@
1
- require 'vedeu/exceptions'
2
1
  require 'vedeu/models/all'
2
+ require 'vedeu/storage/store'
3
3
  require 'vedeu/support/common'
4
4
 
5
5
  module Vedeu
@@ -14,7 +14,7 @@ module Vedeu
14
14
  class Repository
15
15
 
16
16
  include Vedeu::Common
17
- include Enumerable
17
+ include Vedeu::Store
18
18
 
19
19
  # @!attribute [r] model
20
20
  # @return [void]
@@ -24,21 +24,24 @@ module Vedeu
24
24
  # @return [void]
25
25
  attr_reader :storage
26
26
 
27
+ def self.register_repository(model = nil, storage = {})
28
+ new(model, storage).tap do |klass|
29
+ Vedeu::Repositories.register(klass.repository)
30
+ end
31
+ end
32
+
27
33
  # Returns a new instance of Vedeu::Repository.
28
34
  #
29
35
  # @param model [Class]
30
36
  # @param storage [Class|Hash]
31
37
  # @return [Vedeu::Repository]
32
38
  def initialize(model = nil, storage = {})
33
- @model = model
34
- @storage = storage
39
+ @model = model
40
+ @storage = storage
35
41
  end
36
42
 
37
- # Return the whole repository.
38
- #
39
- # @return [Array|Hash|Set]
40
- def all
41
- storage
43
+ def repository
44
+ self.class # .name
42
45
  end
43
46
 
44
47
  # Return the model for the interface currently in focus.
@@ -48,27 +51,22 @@ module Vedeu
48
51
  find_or_create(Vedeu.focus) if Vedeu.focus
49
52
  end
50
53
 
51
- # @return [Enumerator]
52
- def each(&block)
53
- storage.each(&block)
54
- end
55
-
56
- # Return a boolean indicating whether the storage is empty.
54
+ # Find the model by name.
57
55
  #
58
- # @return [Boolean]
59
- def empty?
60
- storage.empty?
56
+ # @param name [String]
57
+ # @return [Hash<String => Object>|NilClass]
58
+ def find(name)
59
+ storage[name]
61
60
  end
62
61
 
63
- # Find the model attributes by name.
62
+ # Find the model attributes by name, raises an exception if the model cannot
63
+ # be found.
64
64
  #
65
65
  # @param name [String]
66
66
  # @raise [ModelNotFound] When the model cannot be found with this name.
67
67
  # @return [Hash<String => Object>]
68
- def find(name)
69
- storage.fetch(name) do
70
- fail ModelNotFound, "Cannot find model by name: '#{name}'"
71
- end
68
+ def find!(name)
69
+ find(name) || fail(ModelNotFound, "Cannot find model by name: '#{name}'")
72
70
  end
73
71
 
74
72
  # Find a model by name, registers the model by name if not found.
@@ -80,7 +78,8 @@ module Vedeu
80
78
  find(name)
81
79
 
82
80
  else
83
- Vedeu.log(type: :store, message: "Model (#{model}) not found, registering: '#{name}'")
81
+ Vedeu.log(type: :store,
82
+ message: "Model (#{model}) not found, registering: '#{name}'")
84
83
 
85
84
  model.new(name).store
86
85
  end
@@ -131,13 +130,6 @@ module Vedeu
131
130
  alias_method :delete, :remove
132
131
  alias_method :deregister, :remove
133
132
 
134
- # Reset the repository.
135
- #
136
- # @return [Array|Hash|Set]
137
- def reset
138
- @storage = in_memory
139
- end
140
-
141
133
  # Stores the model instance by name in the repository of the model.
142
134
  #
143
135
  # @param model [void] A model instance.
@@ -145,9 +137,9 @@ module Vedeu
145
137
  # @return [void] The model instance which was stored.
146
138
  def store(model)
147
139
  fail MissingRequired, "Cannot store model '#{model.class}' without a " \
148
- "name attribute." unless defined_value?(model.name)
140
+ 'name attribute.' unless defined_value?(model.name)
149
141
 
150
- Vedeu.log(type: log_type(model), message: "#{model.class.name}: '#{model.name}'")
142
+ log_store(model)
151
143
 
152
144
  storage[model.name] = model
153
145
  end
@@ -158,13 +150,7 @@ module Vedeu
158
150
  # @param name [String]
159
151
  # @return [|NilClass]
160
152
  def use(name)
161
- if registered?(name)
162
- find(name)
163
-
164
- else
165
- nil
166
-
167
- end
153
+ find(name) if registered?(name)
168
154
  end
169
155
 
170
156
  private
@@ -175,14 +161,10 @@ module Vedeu
175
161
  end
176
162
 
177
163
  # @return [String]
178
- def log_type(model)
179
- if registered?(model.name)
180
- :update
164
+ def log_store(model)
165
+ type = registered?(model.name) ? :update : :create
181
166
 
182
- else
183
- :create
184
-
185
- end
167
+ Vedeu.log(type: type, message: "#{model.class.name}: '#{model.name}'")
186
168
  end
187
169
 
188
170
  end # Repository
@@ -0,0 +1,6 @@
1
+ require 'vedeu/storage/store'
2
+
3
+ require 'vedeu/storage/associative_store'
4
+ require 'vedeu/storage/conveyor_store'
5
+ require 'vedeu/storage/fifo_store'
6
+
@@ -0,0 +1,47 @@
1
+ module Vedeu
2
+
3
+ # Name/Value storage.
4
+ #
5
+ # name: [value]
6
+ #
7
+ class AssociativeStore
8
+
9
+ include Vedeu::Store
10
+
11
+ # @param storage [Hash]
12
+ # @return [Vedeu::AssociativeStore]
13
+ def initialize(storage = {})
14
+ @storage = storage
15
+ end
16
+
17
+ # @param name [String]
18
+ def load(name)
19
+ return nil if empty?
20
+
21
+ storage[name]
22
+ end
23
+
24
+ # @param data [Object]
25
+ # @param name [String|Symbol]
26
+ def save(data, name = nil)
27
+ if name
28
+ storage[name] = data
29
+
30
+ elsif data.respond_to?(:name)
31
+ storage[data.name] = data
32
+
33
+ end
34
+
35
+ storage
36
+ end
37
+
38
+ private
39
+
40
+ # @return [Hash]
41
+ def in_memory
42
+ {}
43
+ end
44
+
45
+ end # AssociativeStore
46
+
47
+ end # Vedeu
@@ -0,0 +1,69 @@
1
+ module Vedeu
2
+
3
+ # Conveyor belt like storage. The belt can move forward (`load_next`) or
4
+ # backwards (`load_previous`), or a named entry can be retrieved.
5
+ #
6
+ class ConveyorStore
7
+
8
+ include Vedeu::Store
9
+
10
+ # @param storage [Array]
11
+ # @return [Vedeu::ConveyorStore]
12
+ def initialize(storage = [])
13
+ @storage = storage
14
+ end
15
+
16
+ # @return [Object]
17
+ def load
18
+ storage.first
19
+ end
20
+ alias_method :current, :load
21
+
22
+ # @param name [String]
23
+ # @return [Object]
24
+ def load_named(name)
25
+ return nil if empty?
26
+
27
+ return nil unless storage.include?(name)
28
+
29
+ storage.rotate!(storage.index(name))
30
+
31
+ load
32
+ end
33
+
34
+ # @return [Object]
35
+ def load_next
36
+ storage.rotate!
37
+
38
+ load
39
+ end
40
+
41
+ # @return [Object]
42
+ def load_previous
43
+ storage.rotate!(-1)
44
+
45
+ load
46
+ end
47
+
48
+ # @param data [Object]
49
+ # @param front [Boolean]
50
+ def save(data, front = false)
51
+ if front
52
+ storage.push(data)
53
+
54
+ else
55
+ storage.unshift(data)
56
+
57
+ end
58
+ end
59
+
60
+ private
61
+
62
+ # @return [Array]
63
+ def in_memory
64
+ []
65
+ end
66
+
67
+ end # ConveyorStore
68
+
69
+ end # Vedeu
@@ -0,0 +1,37 @@
1
+ module Vedeu
2
+
3
+ # First-in first-out storage.
4
+ #
5
+ # in -> [3] -> [2] -> [1] -> out
6
+ #
7
+ class FifoStore
8
+
9
+ include Vedeu::Store
10
+
11
+ # @param storage [Array]
12
+ # @return [Vedeu::FifoStore]
13
+ def initialize(storage = [])
14
+ @storage = storage
15
+ end
16
+
17
+ # @return [Object]
18
+ def load
19
+ storage.pop
20
+ end
21
+
22
+ # @param data [Object]
23
+ # @return [Array<Object>]
24
+ def save(data)
25
+ storage.unshift(data)
26
+ end
27
+
28
+ private
29
+
30
+ # @return [Array]
31
+ def in_memory
32
+ []
33
+ end
34
+
35
+ end # FifoStore
36
+
37
+ end # Vedeu
@@ -0,0 +1,58 @@
1
+ module Vedeu
2
+
3
+ # Provides generic repository related behaviour.
4
+ #
5
+ module Store
6
+
7
+ include Enumerable
8
+
9
+ # @param block [Proc]
10
+ # @return [Enumerator]
11
+ def each(&block)
12
+ storage.each(&block)
13
+ end
14
+
15
+ # Returns a boolean indicating whether the named model is registered.
16
+ #
17
+ # @param name [String]
18
+ # @return [Boolean]
19
+ def exists?(name)
20
+ return false if empty? || name.nil? || name.empty?
21
+
22
+ storage.include?(name)
23
+ end
24
+ alias_method :registered?, :exists?
25
+
26
+ # Return a boolean indicating whether the storage is empty.
27
+ #
28
+ # @return [Boolean]
29
+ def empty?
30
+ storage.empty?
31
+ end
32
+
33
+ # Remove all currently stored data.
34
+ #
35
+ # @return [Array|Hash|Set]
36
+ def reset
37
+ @storage = in_memory
38
+ end
39
+
40
+ # Return the number of entries stored.
41
+ #
42
+ # @return [Fixnum]
43
+ def size
44
+ storage.size
45
+ end
46
+
47
+ # Return whole repository; provides raw access to the storage for this
48
+ # repository.
49
+ #
50
+ # @return [Array|Hash|Set]
51
+ def storage
52
+ @storage ||= in_memory
53
+ end
54
+ alias_method :all, :storage
55
+
56
+ end # Store
57
+
58
+ end # Vedeu
@@ -1,10 +1,5 @@
1
- require 'vedeu/support/coercions'
2
- require 'vedeu/support/common'
3
- require 'vedeu/support/sentence'
4
- require 'vedeu/support/template'
5
- require 'vedeu/support/terminal'
6
- require 'vedeu/support/trace'
7
- require 'vedeu/support/visible'
8
-
9
- module Vedeu
10
- end # Vedeu
1
+ require_relative 'common'
2
+ require_relative 'template'
3
+ require_relative 'terminal'
4
+ require_relative 'trace'
5
+ require_relative 'visibility'