vedeu 0.4.62 → 0.4.63

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 (66) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vedeu/all.rb +6 -5
  3. data/lib/vedeu/api.rb +5 -128
  4. data/lib/vedeu/application/application_controller.rb +0 -2
  5. data/lib/vedeu/application/application_helper.rb +0 -2
  6. data/lib/vedeu/application/application_view.rb +0 -2
  7. data/lib/vedeu/application/controller.rb +1 -1
  8. data/lib/vedeu/bindings/application.rb +12 -4
  9. data/lib/vedeu/bindings/system.rb +4 -4
  10. data/lib/vedeu/bindings/visibility.rb +6 -2
  11. data/lib/vedeu/buffers/buffer.rb +1 -1
  12. data/lib/vedeu/buffers/display_buffer.rb +2 -2
  13. data/lib/vedeu/cli/generator/templates/application/Gemfile +1 -1
  14. data/lib/vedeu/cli/generator/templates/application/application.erb +1 -1
  15. data/lib/vedeu/cli/generator/templates/application/config/configuration.erb +2 -2
  16. data/lib/vedeu/cli/generator/view.rb +2 -2
  17. data/lib/vedeu/colours/colour.rb +1 -1
  18. data/lib/vedeu/colours/colour_translator.rb +2 -2
  19. data/lib/vedeu/configuration/api.rb +1 -1
  20. data/lib/vedeu/configuration/configuration.rb +1 -1
  21. data/lib/vedeu/cursor/refresh_cursor.rb +1 -1
  22. data/lib/vedeu/distributed/server.rb +1 -1
  23. data/lib/vedeu/dsl/border.rb +1 -1
  24. data/lib/vedeu/dsl/geometry.rb +7 -6
  25. data/lib/vedeu/dsl/view.rb +3 -3
  26. data/lib/vedeu/events/event.rb +1 -1
  27. data/lib/vedeu/events/trigger.rb +1 -1
  28. data/lib/vedeu/exceptions.rb +14 -0
  29. data/lib/vedeu/geometry/dimension.rb +1 -1
  30. data/lib/vedeu/geometry/geometry.rb +2 -2
  31. data/lib/vedeu/geometry/position_validator.rb +1 -1
  32. data/lib/vedeu/input/input.rb +6 -5
  33. data/lib/vedeu/input/keymap.rb +3 -3
  34. data/lib/vedeu/input/mapper.rb +3 -3
  35. data/lib/vedeu/internal_api.rb +147 -0
  36. data/lib/vedeu/models/char.rb +2 -2
  37. data/lib/vedeu/models/focus.rb +1 -1
  38. data/lib/vedeu/models/line.rb +1 -1
  39. data/lib/vedeu/models/stream.rb +1 -1
  40. data/lib/vedeu/output/esc.rb +1 -1
  41. data/lib/vedeu/output/presentation.rb +9 -9
  42. data/lib/vedeu/output/refresh.rb +1 -1
  43. data/lib/vedeu/output/renderers.rb +1 -1
  44. data/lib/vedeu/output/text.rb +1 -1
  45. data/lib/vedeu/output/viewport.rb +1 -1
  46. data/lib/vedeu/repositories.rb +1 -1
  47. data/lib/vedeu/repositories/repository.rb +4 -4
  48. data/lib/vedeu/{application.rb → runtime/application.rb} +0 -0
  49. data/lib/vedeu/{bootstrap.rb → runtime/bootstrap.rb} +0 -0
  50. data/lib/vedeu/{launcher.rb → runtime/launcher.rb} +1 -1
  51. data/lib/vedeu/{main_loop.rb → runtime/main_loop.rb} +1 -1
  52. data/lib/vedeu/{router.rb → runtime/router.rb} +57 -4
  53. data/lib/vedeu/terminal.rb +1 -1
  54. data/lib/vedeu/version.rb +1 -1
  55. data/test/lib/vedeu/api_test.rb +1 -15
  56. data/test/lib/vedeu/bindings/application_test.rb +3 -3
  57. data/test/lib/vedeu/internal_api_test.rb +25 -0
  58. data/test/lib/vedeu/output/clear/named_group_test.rb +8 -7
  59. data/test/lib/vedeu/output/presentation_test.rb +45 -0
  60. data/test/lib/vedeu/output/renderers_test.rb +14 -4
  61. data/test/lib/vedeu/{application_test.rb → runtime/application_test.rb} +0 -0
  62. data/test/lib/vedeu/{bootstrap_test.rb → runtime/bootstrap_test.rb} +11 -0
  63. data/test/lib/vedeu/{launcher_test.rb → runtime/launcher_test.rb} +0 -0
  64. data/test/lib/vedeu/{main_loop_test.rb → runtime/main_loop_test.rb} +0 -0
  65. data/test/lib/vedeu/{router_test.rb → runtime/router_test.rb} +13 -1
  66. metadata +20 -17
@@ -41,7 +41,7 @@ module Vedeu
41
41
  #
42
42
  # @param group_name [String] The name of the group to be refreshed.
43
43
  # @return [Array|Vedeu::ModelNotFound] A collection of the names of
44
- # interfaces refreshed, or an exception if the group was not found.
44
+ # interfaces refreshed, or an exception when the group was not found.
45
45
  def by_group(group_name)
46
46
  Vedeu.timer("Refresh Group: '#{group_name}'") do
47
47
  Vedeu::RefreshGroup.by_name(group_name)
@@ -26,7 +26,7 @@ module Vedeu
26
26
  threads = storage.map do |renderer|
27
27
  Thread.new(renderer) do
28
28
  mutex.synchronize do
29
- Vedeu.log(type: :debug,
29
+ Vedeu.log(type: :output,
30
30
  message: "Renderer: '#{renderer.class.name}'")
31
31
 
32
32
  renderer.render(output)
@@ -133,7 +133,7 @@ module Vedeu
133
133
  @line ||= Vedeu::Line.build(parent: parent)
134
134
  end
135
135
 
136
- # Returns the model option if set.
136
+ # Returns the model option when set.
137
137
  #
138
138
  # @return [Vedeu::Interface|Vedeu::Line|Vedeu::Null::Generic|Vedeu::Stream]
139
139
  def model
@@ -44,7 +44,7 @@ module Vedeu
44
44
  @interface = interface
45
45
  end
46
46
 
47
- # Returns the interface with border (if enabled) and the content for the
47
+ # Returns the interface with border (when enabled) and the content for the
48
48
  # interface.
49
49
  #
50
50
  # @return [Array<Array<String>>]
@@ -21,7 +21,7 @@ module Vedeu
21
21
  all.map do |repository|
22
22
  registered = repository.send(:registered)
23
23
 
24
- Vedeu.log(type: :debug,
24
+ Vedeu.log(type: :store,
25
25
  message: "Repository '#{repository.class.name}':" \
26
26
  " #{registered.inspect}")
27
27
 
@@ -85,8 +85,8 @@ module Vedeu
85
85
  storage[name]
86
86
  end
87
87
 
88
- # Find the model attributes by name, raises an exception if the model cannot
89
- # be found.
88
+ # Find the model attributes by name, raises an exception when the model
89
+ # cannot be found.
90
90
  #
91
91
  # @param name [String]
92
92
  # @raise [Vedeu::ModelNotFound] When the model cannot be found with this
@@ -97,7 +97,7 @@ module Vedeu
97
97
  "Cannot find model by name: '#{name}'")
98
98
  end
99
99
 
100
- # Find a model by name, registers the model by name if not found.
100
+ # Find a model by name, registers the model by name when not found.
101
101
  #
102
102
  # @param name [String]
103
103
  # @return [void]
@@ -131,7 +131,7 @@ module Vedeu
131
131
  storage.include?(name)
132
132
  end
133
133
 
134
- # Returns the storage with the named model removed, or false if the model
134
+ # Returns the storage with the named model removed, or false when the model
135
135
  # does not exist.
136
136
  #
137
137
  # @param name [String]
@@ -65,7 +65,7 @@ module Vedeu
65
65
 
66
66
  # Alters the STD[IN|OUT|ERR] to those requested by the client application,
67
67
  # then starts the application. If an uncaught exception occurs during the
68
- # application runtime, we exit ungracefully with the error message if any.
68
+ # application runtime, we exit ungracefully with any error message(s).
69
69
  #
70
70
  # @return [void]
71
71
  def execute!
@@ -25,7 +25,7 @@ module Vedeu
25
25
  safe_exit_point!
26
26
  end
27
27
  rescue Vedeu::VedeuInterrupt
28
- Vedeu.log(type: :debug,
28
+ Vedeu.log(type: :info,
29
29
  message: 'Vedeu execution interrupted, exiting.')
30
30
  end
31
31
  # :nocov:
@@ -8,8 +8,12 @@ module Vedeu
8
8
 
9
9
  extend self
10
10
 
11
+ # Registers a controller with the given controller name for the client
12
+ # application.
13
+ #
11
14
  # @param controller_name [Symbol]
12
15
  # @param klass [String]
16
+ # @raise [Vedeu::MissingRequired] When the controller name is not given.
13
17
  # @return [void]
14
18
  def add_controller(controller_name, klass)
15
19
  unless present?(controller_name)
@@ -28,8 +32,13 @@ module Vedeu
28
32
  storage
29
33
  end
30
34
 
35
+ # Registers an action to the given controller name for the client
36
+ # application.
37
+ #
31
38
  # @param controller_name [Symbol]
32
39
  # @param action_name [Symbol]
40
+ # @raise [Vedeu::MissingRequired] When the controller name or action name is
41
+ # not given.
33
42
  # @return [void]
34
43
  def add_action(controller_name, action_name)
35
44
  if present?(controller_name) && present?(action_name)
@@ -51,24 +60,35 @@ module Vedeu
51
60
  end
52
61
  end
53
62
 
63
+ # Instruct Vedeu to load the client application controller action with
64
+ # parameters.
65
+ #
66
+ # @example
67
+ # Vedeu.goto(controller_name, action_name, args)
68
+ #
54
69
  # @param controller_name [Symbol]
55
70
  # @param action_name [Symbol]
56
71
  # @param args [void]
72
+ # @raise [Vedeu::ModelNotFound] When the controller is not registered.
57
73
  # @return [void]
58
74
  def goto(controller_name, action_name, **args)
59
- unless registered?(controller_name)
60
- fail Vedeu::ModelNotFound, "#{controller_name} is not registered."
75
+ if action_defined?(action_name, controller_name)
76
+ controller_with(controller_name).send(action_name, args)
61
77
  end
62
-
63
- controller_with(controller_name).send(action_name, args)
64
78
  end
79
+ alias_method :action, :goto
65
80
 
81
+ # Returns a boolean indicating whether the given controller name is already
82
+ # registered.
83
+ #
66
84
  # @param controller_name [Symbol]
67
85
  # @return [Boolean]
68
86
  def registered?(controller_name)
69
87
  storage.key?(controller_name)
70
88
  end
71
89
 
90
+ # Removes all stored controllers with their respective actions.
91
+ #
72
92
  # @return [Hash<void>]
73
93
  def reset!
74
94
  @storage = in_memory
@@ -77,13 +97,38 @@ module Vedeu
77
97
 
78
98
  private
79
99
 
100
+ # Returns a boolean indicating whether the given action name is defined for
101
+ # the given controller.
102
+ #
103
+ # @param action_name [Symbol]
104
+ # @param controller_name [Symbol]
105
+ # @return [Boolean]
106
+ def action_defined?(action_name, controller_name)
107
+ if registered?(controller_name)
108
+ return true if storage[controller_name][:actions].include?(action_name)
109
+
110
+ fail Vedeu::ActionNotFound,
111
+ "#{action_name} is not registered for #{controller_name}."
112
+
113
+ else
114
+ fail Vedeu::ControllerNotFound, "#{controller_name} is not registered."
115
+
116
+ end
117
+ end
118
+
119
+ # Instantiate the given controller by name.
120
+ #
80
121
  # @param controller_name [Symbol]
81
122
  # @return [void]
82
123
  def controller_with(controller_name)
83
124
  Object.const_get(klass_for(controller_name)).new
84
125
  end
85
126
 
127
+ # Fetch the class for the controller by name.
128
+ #
86
129
  # @param controller_name [Symbol]
130
+ # @raise [Vedeu::MissingRequired] When the given controller name does not
131
+ # have a class defined.
87
132
  # @return [String]
88
133
  def klass_for(controller_name)
89
134
  if registered?(controller_name) && klass_defined?(controller_name)
@@ -96,17 +141,25 @@ module Vedeu
96
141
  end
97
142
  end
98
143
 
144
+ # Returns a boolean indicating whether the given controller name has a class
145
+ # defined.
146
+ #
99
147
  # @param controller_name [Symbol]
100
148
  # @return [Boolean]
101
149
  def klass_defined?(controller_name)
102
150
  present?(storage[controller_name][:klass])
103
151
  end
104
152
 
153
+ # Returns all the stored controllers and their respective actions.
154
+ #
105
155
  # @return [Hash<Symbol => Hash<Symbol => String|Array<Symbol>>>]
106
156
  def storage
107
157
  @storage ||= in_memory
108
158
  end
109
159
 
160
+ # Returns an empty collection ready for the storing of client application
161
+ # controllers and actions.
162
+ #
110
163
  # @return [Hash<void>]
111
164
  def in_memory
112
165
  {}
@@ -32,7 +32,7 @@ module Vedeu
32
32
  #
33
33
  # @return [String]
34
34
  def input
35
- Vedeu.log(type: :debug, message: 'Waiting for user input...')
35
+ Vedeu.log(type: :input, message: 'Waiting for user input...')
36
36
 
37
37
  keys_or_cmd = if raw_mode?
38
38
  keys = console.getch
@@ -1,6 +1,6 @@
1
1
  module Vedeu
2
2
 
3
3
  # The current version of Vedeu.
4
- VERSION = '0.4.62'
4
+ VERSION = '0.4.63'
5
5
 
6
6
  end
@@ -4,13 +4,9 @@ module Vedeu
4
4
 
5
5
  describe API do
6
6
 
7
- it { Vedeu.must_respond_to(:background_colours) }
8
- it { Vedeu.must_respond_to(:borders) }
9
- it { Vedeu.must_respond_to(:buffers) }
10
7
  it { Vedeu.must_respond_to(:configure) }
11
8
  it { Vedeu.must_respond_to(:configuration) }
12
9
  it { Vedeu.must_respond_to(:cursor) }
13
- it { Vedeu.must_respond_to(:cursors) }
14
10
  it { Vedeu.must_respond_to(:drb_restart) }
15
11
  it { Vedeu.must_respond_to(:drb_start) }
16
12
  it { Vedeu.must_respond_to(:drb_status) }
@@ -26,29 +22,19 @@ module Vedeu
26
22
  it { Vedeu.must_respond_to(:bind) }
27
23
  it { Vedeu.must_respond_to(:bound?) }
28
24
  it { Vedeu.must_respond_to(:unbind) }
29
- it { Vedeu.must_respond_to(:events) }
30
25
  it { Vedeu.must_respond_to(:focus) }
31
26
  it { Vedeu.must_respond_to(:focus_by_name) }
32
27
  it { Vedeu.must_respond_to(:focussed?) }
33
28
  it { Vedeu.must_respond_to(:focus_next) }
34
29
  it { Vedeu.must_respond_to(:focus_previous) }
35
- it { Vedeu.must_respond_to(:foreground_colours) }
36
- it { Vedeu.must_respond_to(:geometries) }
37
- it { Vedeu.must_respond_to(:groups) }
38
- it { Vedeu.must_respond_to(:interfaces) }
39
- it { Vedeu.must_respond_to(:keymaps) }
30
+ it { Vedeu.must_respond_to(:goto) }
40
31
  it { Vedeu.must_respond_to(:log) }
41
32
  it { Vedeu.must_respond_to(:log_stdout) }
42
33
  it { Vedeu.must_respond_to(:log_stderr) }
43
34
  it { Vedeu.must_respond_to(:keypress) }
44
35
  it { Vedeu.must_respond_to(:menu) }
45
- it { Vedeu.must_respond_to(:menus) }
46
- it { Vedeu.must_respond_to(:renderer) }
47
- it { Vedeu.must_respond_to(:renderers) }
48
36
  it { Vedeu.must_respond_to(:height) }
49
37
  it { Vedeu.must_respond_to(:width) }
50
- it { Vedeu.must_respond_to(:resize) }
51
- it { Vedeu.must_respond_to(:timer) }
52
38
  it { Vedeu.must_respond_to(:trigger) }
53
39
  it { Vedeu.must_respond_to(:exit) }
54
40
  it { Vedeu.must_respond_to(:clear) }
@@ -7,10 +7,10 @@ module Vedeu
7
7
  describe Application do
8
8
 
9
9
  context 'the application specific events are defined' do
10
- it { Vedeu.bound?(:_action_).must_equal(true) }
10
+ it { Vedeu.bound?(:_goto_).must_equal(true) }
11
11
  end
12
12
 
13
- describe '.action!' do
13
+ describe '.goto!' do
14
14
  let(:controller) { :some_controller }
15
15
  let(:action) { :show_basket }
16
16
  let(:args) {
@@ -22,7 +22,7 @@ module Vedeu
22
22
 
23
23
  before { Vedeu::Router.stubs(:goto) }
24
24
 
25
- subject { Vedeu.trigger(:_action_, controller, action, **args) }
25
+ subject { Vedeu.trigger(:_goto_, controller, action, **args) }
26
26
 
27
27
  it {
28
28
  Vedeu::Router.expects(:goto)
@@ -0,0 +1,25 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ describe InternalAPI do
6
+
7
+ it { Vedeu.must_respond_to(:background_colours) }
8
+ it { Vedeu.must_respond_to(:borders) }
9
+ it { Vedeu.must_respond_to(:buffers) }
10
+ it { Vedeu.must_respond_to(:cursors) }
11
+ it { Vedeu.must_respond_to(:events) }
12
+ it { Vedeu.must_respond_to(:foreground_colours) }
13
+ it { Vedeu.must_respond_to(:geometries) }
14
+ it { Vedeu.must_respond_to(:groups) }
15
+ it { Vedeu.must_respond_to(:interfaces) }
16
+ it { Vedeu.must_respond_to(:keymaps) }
17
+ it { Vedeu.must_respond_to(:menus) }
18
+ it { Vedeu.must_respond_to(:renderer) }
19
+ it { Vedeu.must_respond_to(:renderers) }
20
+ it { Vedeu.must_respond_to(:resize) }
21
+ it { Vedeu.must_respond_to(:timer) }
22
+
23
+ end # InternalAPI
24
+
25
+ end # Vedeu
@@ -16,22 +16,23 @@ module Vedeu
16
16
  end
17
17
 
18
18
  describe '.render' do
19
- it { described.must_respond_to(:by_group) }
20
- it { described.must_respond_to(:clear_by_group) }
21
- it { described.must_respond_to(:render) }
22
- end
23
-
24
- describe '#render' do
25
19
  let(:group) { Vedeu::Group.new(members: [_name]) }
26
20
 
27
21
  before { Vedeu.groups.stubs(:by_name).returns(group) }
28
22
 
29
- subject { instance.render }
23
+ subject { described.render(_name) }
30
24
 
31
25
  it {
32
26
  Vedeu::Clear::NamedInterface.expects(:render).with(_name)
33
27
  subject
34
28
  }
29
+
30
+ it { described.must_respond_to(:by_group) }
31
+ it { described.must_respond_to(:clear_by_group) }
32
+ end
33
+
34
+ describe '#render' do
35
+ it { instance.must_respond_to(:render) }
35
36
  end
36
37
 
37
38
  end # NamedGroup
@@ -103,12 +103,41 @@ module Vedeu
103
103
 
104
104
  it { subject.must_be_instance_of(Vedeu::Background) }
105
105
  it { subject.colour.must_equal('#330000') }
106
+
107
+ context 'when no parent colour is set' do
108
+ before { includer.stubs(:parent).returns(nil) }
109
+
110
+ it { subject.colour.must_equal('') }
111
+ end
112
+ end
113
+
114
+ describe '#parent_colour' do
115
+ subject { includer.parent_colour }
116
+
117
+ context 'when a parent is available' do
118
+ it { subject.must_be_instance_of(Vedeu::Colour) }
119
+ it { subject.background.must_be_instance_of(Vedeu::Background) }
120
+ it { subject.foreground.must_be_instance_of(Vedeu::Foreground) }
121
+ end
122
+
123
+ context 'when a parent is not available' do
124
+ before { includer.stubs(:parent).returns(nil) }
125
+
126
+ it { subject.must_equal(nil) }
127
+ end
106
128
  end
107
129
 
108
130
  describe '#parent_foreground' do
109
131
  subject { includer.parent_foreground }
110
132
 
111
133
  it { subject.must_be_instance_of(Vedeu::Foreground) }
134
+ it { subject.colour.must_equal('#00aadd') }
135
+
136
+ context 'when no parent colour is set' do
137
+ before { includer.stubs(:parent).returns(nil) }
138
+
139
+ it { subject.colour.must_equal('') }
140
+ end
112
141
  end
113
142
 
114
143
  describe '#colour' do
@@ -125,6 +154,22 @@ module Vedeu
125
154
  it { subject.must_be_instance_of(Colour) }
126
155
  end
127
156
 
157
+ describe '#parent_style' do
158
+ subject { includer.parent_style }
159
+
160
+ it { subject.must_be_instance_of(Vedeu::Style) }
161
+
162
+ context 'when a parent is available' do
163
+ it { subject.value.must_equal(['bold']) }
164
+ end
165
+
166
+ context 'when a parent is not available' do
167
+ before { includer.stubs(:parent).returns(nil) }
168
+
169
+ it { subject.value.must_equal(nil) }
170
+ end
171
+ end
172
+
128
173
  describe '#style' do
129
174
  subject { includer.style }
130
175
 
@@ -3,13 +3,13 @@ require 'test_helper'
3
3
  module Vedeu
4
4
 
5
5
  class DummyRenderer
6
- def self.render
6
+ def self.render(*output)
7
7
  :dummy
8
8
  end
9
9
  end
10
10
 
11
11
  class FooRenderer
12
- def self.render
12
+ def self.render(*output)
13
13
  :foo
14
14
  end
15
15
  end
@@ -55,11 +55,21 @@ module Vedeu
55
55
  end
56
56
 
57
57
  describe '.render' do
58
- let(:args) {}
58
+ let(:output) {}
59
59
 
60
- subject { described.render(args) }
60
+ before do
61
+ Vedeu::Renderers.reset
62
+ Vedeu::Renderers.renderer(DummyRenderer)
63
+ end
64
+
65
+ subject { described.render(output) }
61
66
 
62
67
  it { subject.must_be_instance_of(Array) }
68
+
69
+ it {
70
+ DummyRenderer.expects(:render).with(output)
71
+ subject
72
+ }
63
73
  end
64
74
 
65
75
  describe '.renderer' do