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,5 +1,5 @@
1
- require_relative 'application'
2
- require_relative 'configuration'
1
+ require 'vedeu/application'
2
+ require 'vedeu/configuration'
3
3
 
4
4
  module Vedeu
5
5
  class Launcher
@@ -1,6 +1,6 @@
1
1
  require 'virtus'
2
2
 
3
- require_relative '../../repository/interface_repository'
3
+ require 'vedeu/support/persistence'
4
4
 
5
5
  module Vedeu
6
6
  class InterfaceCollection < Virtus::Attribute
@@ -8,7 +8,7 @@ module Vedeu
8
8
  return [] if values.nil? || values.empty?
9
9
 
10
10
  [values].flatten.map do |value|
11
- InterfaceRepository.update(value.fetch(:name, nil), value)
11
+ Persistence.update(value.fetch(:name, nil), value)
12
12
  end
13
13
  end
14
14
  end
@@ -1,7 +1,7 @@
1
1
  require 'virtus'
2
2
 
3
- require_relative 'collection'
4
- require_relative '../line'
3
+ require 'vedeu/models/attributes/collection'
4
+ require 'vedeu/models/line'
5
5
 
6
6
  module Vedeu
7
7
  class LineCollection < Virtus::Attribute
@@ -1,7 +1,7 @@
1
1
  require 'virtus'
2
2
 
3
- require_relative 'collection'
4
- require_relative '../stream'
3
+ require 'vedeu/models/attributes/collection'
4
+ require 'vedeu/models/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 '../support/esc'
4
+ require 'vedeu/support/esc'
5
5
 
6
6
  module Vedeu
7
7
  class Colour
@@ -1,7 +1,7 @@
1
1
  require 'json'
2
2
  require 'virtus'
3
3
 
4
- require_relative 'attributes/interface_collection'
4
+ require 'vedeu/models/attributes/interface_collection'
5
5
 
6
6
  module Vedeu
7
7
  class Composition
@@ -1,14 +1,15 @@
1
1
  require 'json'
2
2
  require 'virtus'
3
3
 
4
- require_relative 'attributes/line_collection'
5
- require_relative 'presentation'
6
- require_relative 'style'
7
- require_relative '../output/clear_interface'
8
- require_relative '../output/render_interface'
9
- require_relative '../support/geometry'
10
- require_relative '../support/queue'
11
- require_relative '../support/terminal'
4
+ require 'vedeu'
5
+ require 'vedeu/models/attributes/line_collection'
6
+ require 'vedeu/models/presentation'
7
+ require 'vedeu/models/style'
8
+ require 'vedeu/output/clear_interface'
9
+ require 'vedeu/output/render_interface'
10
+ require 'vedeu/support/geometry'
11
+ require 'vedeu/support/queue'
12
+ require 'vedeu/support/terminal'
12
13
 
13
14
  module Vedeu
14
15
  class Interface
@@ -21,13 +22,18 @@ module Vedeu
21
22
  attribute :lines, LineCollection
22
23
  attribute :y, Integer, default: 1
23
24
  attribute :x, Integer, default: 1
24
- attribute :z, Integer, default: 1
25
25
  attribute :width, Integer, default: Terminal.width
26
26
  attribute :height, Integer, default: Terminal.height
27
27
  attribute :current, String, default: ''
28
28
  attribute :cursor, Boolean, default: true
29
29
  attribute :centred, Boolean, default: false
30
30
 
31
+ def initialize(attributes = {})
32
+ Vedeu.events.on(:refresh) { refresh }
33
+
34
+ super
35
+ end
36
+
31
37
  def enqueue
32
38
  super(self.to_s)
33
39
  end
@@ -51,6 +57,9 @@ module Vedeu
51
57
  self.current
52
58
 
53
59
  end
60
+ Terminal.output(self.current)
61
+
62
+ self.current
54
63
  end
55
64
 
56
65
  def to_json(*args)
@@ -61,7 +70,6 @@ module Vedeu
61
70
  lines: lines,
62
71
  y: y,
63
72
  x: x,
64
- z: z,
65
73
  width: width,
66
74
  height: height,
67
75
  cursor: cursor
@@ -1,9 +1,9 @@
1
1
  require 'json'
2
2
  require 'virtus'
3
3
 
4
- require_relative 'attributes/stream_collection'
5
- require_relative 'presentation'
6
- require_relative 'style'
4
+ require 'vedeu/models/attributes/stream_collection'
5
+ require 'vedeu/models/presentation'
6
+ require 'vedeu/models/style'
7
7
 
8
8
  module Vedeu
9
9
  class Line
@@ -1,6 +1,6 @@
1
1
  require 'virtus'
2
2
 
3
- require_relative 'colour'
3
+ require 'vedeu/models/colour'
4
4
 
5
5
  module Vedeu
6
6
  module Presentation
@@ -1,8 +1,8 @@
1
1
  require 'json'
2
2
  require 'virtus'
3
3
 
4
- require_relative 'presentation'
5
- require_relative 'style'
4
+ require 'vedeu/models/presentation'
5
+ require 'vedeu/models/style'
6
6
 
7
7
  module Vedeu
8
8
  class Stream
@@ -1,4 +1,4 @@
1
- require_relative '../support/esc'
1
+ require 'vedeu/support/esc'
2
2
 
3
3
  module Vedeu
4
4
  module Style
@@ -1,4 +1,4 @@
1
- require_relative 'clear_interface'
1
+ require 'vedeu/output/clear_interface'
2
2
 
3
3
  module Vedeu
4
4
  class RenderInterface
@@ -1,4 +1,4 @@
1
- require_relative '../models/composition'
1
+ require 'vedeu/models/composition'
2
2
 
3
3
  module Vedeu
4
4
  class Compositor
@@ -1,4 +1,4 @@
1
- require_relative 'text_adaptor'
1
+ require 'vedeu/parsing/text_adaptor'
2
2
 
3
3
  module Vedeu
4
4
  class HashParser
@@ -1,12 +1,14 @@
1
- require_relative '../support/compositor'
2
- require_relative 'hash_parser'
3
- require_relative 'json_parser'
1
+ require 'vedeu/parsing/compositor'
2
+ require 'vedeu/parsing/hash_parser'
3
+ require 'vedeu/parsing/json_parser'
4
4
 
5
5
  module Vedeu
6
- class ParseError < StandardError; end
6
+ ParseError = Class.new(StandardError)
7
7
 
8
8
  class Parser
9
9
  def self.parse(output = {})
10
+ return nil if output.nil? || output.empty?
11
+
10
12
  new(output).parse
11
13
  end
12
14
 
@@ -15,8 +17,6 @@ module Vedeu
15
17
  end
16
18
 
17
19
  def parse
18
- return nil if empty?
19
-
20
20
  Compositor.enqueue(parsed_output)
21
21
  end
22
22
 
@@ -42,9 +42,5 @@ module Vedeu
42
42
  def json?
43
43
  output.is_a?(String)
44
44
  end
45
-
46
- def empty?
47
- output.nil? || output.empty?
48
- end
49
45
  end
50
46
  end
@@ -1,3 +1,6 @@
1
+ require 'vedeu/support/geometry'
2
+ require 'vedeu/support/persistence'
3
+
1
4
  module Vedeu
2
5
  class Builder
3
6
  def self.build(name, &block)
@@ -11,23 +14,30 @@ module Vedeu
11
14
  def build(&block)
12
15
  self.instance_eval(&block)
13
16
 
14
- repository.create(attributes)
15
- end
16
-
17
- def repository
18
- fail StandardError, 'Subclasses implement this.'
17
+ Persistence.create(attributes)
19
18
  end
20
19
 
21
20
  private
22
21
 
23
22
  attr_reader :name
24
23
 
25
- def attributes
26
- user_attributes.merge!(overrides)
24
+ def overrides
25
+ @overrides = if user_attributes[:centred] == true
26
+ { x: geometry.left, y: geometry.top }
27
+ else
28
+ {}
29
+ end
27
30
  end
28
31
 
29
- def overrides
30
- {}
32
+ def geometry
33
+ @_geometry ||= Geometry.new({
34
+ height: user_attributes[:height],
35
+ width: user_attributes[:width],
36
+ })
37
+ end
38
+
39
+ def attributes
40
+ user_attributes.merge!(overrides)
31
41
  end
32
42
 
33
43
  def user_attributes
@@ -1,4 +1,4 @@
1
- require_relative 'translator'
1
+ require 'vedeu/support/translator'
2
2
 
3
3
  module Vedeu
4
4
  module Esc
@@ -3,8 +3,7 @@ module Vedeu
3
3
  def initialize(&block)
4
4
  @handlers = Hash.new { |h, k| h[k] = [] }
5
5
 
6
- log("Events#initialize " \
7
- "self: #{self.object_id}")
6
+ log("self: #{self.object_id}")
8
7
 
9
8
  self.instance_eval(&block) if block_given?
10
9
 
@@ -12,47 +11,44 @@ module Vedeu
12
11
  end
13
12
 
14
13
  def add(object, &block)
15
- log("Events#add " \
16
- "self: #{self.object_id}" \
17
- "menu: #{object.object_id}")
14
+ log("self: #{self.object_id}")
15
+ log("object: #{object.object_id}")
18
16
 
19
- @self_before_instance_eval = eval "self", block.binding
17
+ @self_before_instance_eval = eval 'self', block.binding
20
18
 
21
19
  self.instance_eval(&block)
22
20
  end
23
21
 
24
22
  def on(event, &block)
25
- log("Events#on " \
26
- "self: #{self.object_id} " \
27
- "block: #{block.object_id} " \
28
- "event: #{event.inspect}")
23
+ log("self: #{self.object_id}")
24
+ log("block: #{block.object_id}")
25
+ log("storing: #{event.inspect}")
26
+
29
27
  handlers[event] << block
30
28
  end
31
29
 
32
30
  def trigger(event, *args)
33
31
  handlers[event].each do |handler|
34
- log("Events#trigger " \
35
- "self: #{self.object_id} " \
36
- "handler: #{handler.object_id} " \
37
- "event: #{event.inspect}")
32
+ log("self: #{self.object_id}")
33
+ log("handler: #{handler.object_id}")
34
+ log("running: #{event.inspect}")
35
+
38
36
  handler.call(*args)
39
37
  end
40
38
  end
41
39
 
40
+ # :nocov:
42
41
  def method_missing(method, *args, &block)
43
42
  @self_before_instance_eval.send method, *args, &block
44
43
  end
44
+ # :nocov:
45
45
 
46
46
  private
47
47
 
48
48
  attr_reader :handlers
49
49
 
50
50
  def log(message)
51
- Vedeu.trigger(:_log_, message) if debug?
52
- end
53
-
54
- def debug?
55
- false
51
+ Vedeu.log(sprintf("%42s%s", '', message))
56
52
  end
57
53
  end
58
54
  end
@@ -1,8 +1,8 @@
1
- require_relative 'esc'
2
- require_relative 'terminal'
1
+ require 'vedeu/support/esc'
2
+ require 'vedeu/support/terminal'
3
3
 
4
4
  module Vedeu
5
- class OutOfBoundsError < StandardError; end
5
+ OutOfBoundsError = Class.new(StandardError)
6
6
 
7
7
  class Geometry
8
8
  def initialize(attrs = {})
@@ -1,6 +1,5 @@
1
- require_relative '../support/queue'
2
- require_relative '../support/terminal'
3
- require_relative '../../vedeu'
1
+ require 'vedeu/support/terminal'
2
+ require 'vedeu'
4
3
 
5
4
  module Vedeu
6
5
  class Input
@@ -10,12 +9,14 @@ module Vedeu
10
9
 
11
10
  def capture
12
11
  Vedeu.trigger(:_keypress_, keypress)
13
-
14
- Queue.enqueue(keypress)
15
12
  end
16
13
 
17
14
  private
18
15
 
16
+ def input
17
+ @_input ||= Terminal.input
18
+ end
19
+
19
20
  def keypress
20
21
  key = input
21
22
  translated = case key
@@ -53,9 +54,5 @@ module Vedeu
53
54
 
54
55
  translated
55
56
  end
56
-
57
- def input
58
- @_input ||= Terminal.input
59
- end
60
57
  end
61
58
  end
@@ -1,5 +1,5 @@
1
- require_relative '../../vedeu'
2
- require_relative 'events'
1
+ require 'vedeu'
2
+ require 'vedeu/support/events'
3
3
 
4
4
  module Vedeu
5
5
  class Menu
@@ -47,7 +47,7 @@ module Vedeu
47
47
  def items
48
48
  items = []
49
49
  @collection.each_with_index do |item, index|
50
- if index == @current && index == @selected
50
+ if index == @current && index == @selected
51
51
  items << [true, true, item]
52
52
 
53
53
  elsif index == @current
@@ -0,0 +1,41 @@
1
+ require 'vedeu/models/interface'
2
+
3
+ module Vedeu
4
+ EntityNotFound = Class.new(StandardError)
5
+
6
+ module Persistence
7
+ extend self
8
+
9
+ def update(name, attributes = {})
10
+ interface = query(name)
11
+ interface.attributes = attributes
12
+ interface
13
+ rescue EntityNotFound
14
+ create(attributes)
15
+ end
16
+
17
+ def create(attributes)
18
+ storage.store(attributes[:name], Interface.new(attributes))
19
+ end
20
+
21
+ def query(value)
22
+ return false if value.nil? || value.empty?
23
+
24
+ storage.select do |name, result|
25
+ return result if name == value
26
+ end
27
+
28
+ fail EntityNotFound, "Interface could not be found."
29
+ end
30
+
31
+ def reset
32
+ @storage = {}
33
+ end
34
+
35
+ private
36
+
37
+ def storage
38
+ @storage ||= {}
39
+ end
40
+ end
41
+ end