vedeu 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vedeu/all.rb +1 -1
  3. data/lib/vedeu/application/controller.rb +2 -2
  4. data/lib/vedeu/bindings.rb +1 -1
  5. data/lib/vedeu/bindings/application.rb +2 -2
  6. data/lib/vedeu/bindings/drb.rb +8 -8
  7. data/lib/vedeu/bindings/menus.rb +11 -11
  8. data/lib/vedeu/bindings/movement.rb +12 -12
  9. data/lib/vedeu/bindings/system.rb +18 -18
  10. data/lib/vedeu/bindings/visibility.rb +9 -9
  11. data/lib/vedeu/colours/colour.rb +1 -1
  12. data/lib/vedeu/common.rb +1 -1
  13. data/lib/vedeu/dsl/composition.rb +8 -3
  14. data/lib/vedeu/dsl/interface.rb +41 -17
  15. data/lib/vedeu/log/debug.rb +5 -1
  16. data/lib/vedeu/log/log.rb +1 -0
  17. data/lib/vedeu/models/interface.rb +3 -2
  18. data/lib/vedeu/plugins.rb +1 -1
  19. data/lib/vedeu/runtime/bootstrap.rb +0 -3
  20. data/lib/vedeu/runtime/launcher.rb +3 -2
  21. data/lib/vedeu/runtime/router.rb +49 -47
  22. data/lib/vedeu/{traps.rb → runtime/traps.rb} +0 -0
  23. data/lib/vedeu/templating/decoder.rb +4 -2
  24. data/lib/vedeu/templating/encoder.rb +4 -2
  25. data/lib/vedeu/templating/view_template.rb +35 -2
  26. data/lib/vedeu/version.rb +1 -1
  27. data/test/lib/vedeu/application/application_view_test.rb +1 -1
  28. data/test/lib/vedeu/application/controller_test.rb +4 -0
  29. data/test/lib/vedeu/bindings_test.rb +2 -0
  30. data/test/lib/vedeu/borders/border_test.rb +28 -40
  31. data/test/lib/vedeu/borders/borders_test.rb +0 -2
  32. data/test/lib/vedeu/borders/render_border_test.rb +11 -13
  33. data/test/lib/vedeu/buffers/buffer_test.rb +12 -5
  34. data/test/lib/vedeu/buffers/display_buffer_test.rb +2 -2
  35. data/test/lib/vedeu/cli/generator/application_test.rb +9 -9
  36. data/test/lib/vedeu/cli/generator/view_test.rb +10 -7
  37. data/test/lib/vedeu/cli/main_test.rb +4 -4
  38. data/test/lib/vedeu/colours/colour_translator_test.rb +2 -4
  39. data/test/lib/vedeu/common_test.rb +8 -0
  40. data/test/lib/vedeu/configuration/configuration_test.rb +4 -4
  41. data/test/lib/vedeu/cursor/cursors_test.rb +4 -4
  42. data/test/lib/vedeu/cursor/move_test.rb +11 -8
  43. data/test/lib/vedeu/cursor/refresh_cursor_test.rb +12 -12
  44. data/test/lib/vedeu/cursor/reposition_test.rb +7 -11
  45. data/test/lib/vedeu/distributed/client_test.rb +4 -4
  46. data/test/lib/vedeu/distributed/server_test.rb +4 -5
  47. data/test/lib/vedeu/dsl/border_test.rb +2 -2
  48. data/test/lib/vedeu/dsl/composition_test.rb +5 -4
  49. data/test/lib/vedeu/dsl/geometry_test.rb +6 -4
  50. data/test/lib/vedeu/dsl/interface_test.rb +9 -27
  51. data/test/lib/vedeu/dsl/use_test.rb +2 -2
  52. data/test/lib/vedeu/events/trigger_test.rb +2 -2
  53. data/test/lib/vedeu/geometry/coordinate_test.rb +9 -9
  54. data/test/lib/vedeu/geometry/geometry_test.rb +8 -2
  55. data/test/lib/vedeu/geometry/position_validator_test.rb +11 -14
  56. data/test/lib/vedeu/input/input_test.rb +5 -5
  57. data/test/lib/vedeu/input/keymap_test.rb +2 -2
  58. data/test/lib/vedeu/log/timer_test.rb +2 -2
  59. data/test/lib/vedeu/models/focus_test.rb +20 -25
  60. data/test/lib/vedeu/models/interface_test.rb +2 -2
  61. data/test/lib/vedeu/models/interfaces_test.rb +7 -5
  62. data/test/lib/vedeu/models/line_test.rb +0 -5
  63. data/test/lib/vedeu/models/menu_test.rb +0 -2
  64. data/test/lib/vedeu/null/geometry_test.rb +1 -4
  65. data/test/lib/vedeu/output/clear/named_interface_test.rb +2 -2
  66. data/test/lib/vedeu/output/esc_test.rb +7 -4
  67. data/test/lib/vedeu/output/output_test.rb +3 -6
  68. data/test/lib/vedeu/output/refresh_test.rb +2 -2
  69. data/test/lib/vedeu/output/renderers/file_test.rb +1 -3
  70. data/test/lib/vedeu/output/renderers/html_test.rb +1 -3
  71. data/test/lib/vedeu/output/renderers/json_test.rb +1 -3
  72. data/test/lib/vedeu/output/renderers_test.rb +2 -2
  73. data/test/lib/vedeu/output/viewport_test.rb +70 -71
  74. data/test/lib/vedeu/repositories/model_test.rb +0 -19
  75. data/test/lib/vedeu/repositories/repository_test.rb +8 -8
  76. data/test/lib/vedeu/runtime/application_test.rb +2 -2
  77. data/test/lib/vedeu/runtime/launcher_test.rb +7 -7
  78. data/test/lib/vedeu/runtime/router_test.rb +33 -33
  79. data/test/lib/vedeu/{traps_test.rb → runtime/traps_test.rb} +2 -2
  80. data/test/lib/vedeu/templating/decoder_test.rb +1 -0
  81. data/test/lib/vedeu/templating/encoder_test.rb +1 -0
  82. data/test/lib/vedeu/templating/template_test.rb +8 -1
  83. data/test/lib/vedeu/templating/view_template_test.rb +108 -22
  84. data/test/lib/vedeu/terminal_mode_test.rb +2 -2
  85. data/test/lib/vedeu/terminal_test.rb +6 -6
  86. data/test/support/helpers/model_test_class.rb +19 -0
  87. metadata +5 -17
  88. data/test/support/templates/background.erb +0 -1
  89. data/test/support/templates/colour.erb +0 -1
  90. data/test/support/templates/foreground.erb +0 -1
  91. data/test/support/templates/multiple.erb +0 -2
  92. data/test/support/templates/plain.erb +0 -1
  93. data/test/support/templates/style.erb +0 -1
@@ -11,7 +11,7 @@ module Vedeu
11
11
 
12
12
  # Setup events relating to visibility. This method is called by Vedeu.
13
13
  #
14
- # @return [void]
14
+ # @return [TrueClass]
15
15
  def setup!
16
16
  clear_group!
17
17
  hide_cursor!
@@ -34,7 +34,7 @@ module Vedeu
34
34
  # Vedeu.trigger(:_clear_group_, name)
35
35
  # Vedeu.clear_by_group(name)
36
36
  #
37
- # @return [void]
37
+ # @return [TrueClass]
38
38
  def clear_group!
39
39
  Vedeu.bind(:_clear_group_) do |name|
40
40
  Vedeu::Clear::NamedGroup.render(name)
@@ -49,7 +49,7 @@ module Vedeu
49
49
  # Vedeu.trigger(:_cursor_hide_, name)
50
50
  # Vedeu.hide_cursor(name)
51
51
  #
52
- # @return [void]
52
+ # @return [TrueClass]
53
53
  def hide_cursor!
54
54
  Vedeu.bind(:_hide_cursor_) do |name|
55
55
  Vedeu::Cursor.hide_cursor(name)
@@ -74,7 +74,7 @@ module Vedeu
74
74
  # Vedeu.trigger(:_hide_interface_, name)
75
75
  # Vedeu.hide_interface(name)
76
76
  #
77
- # @return [void]
77
+ # @return [TrueClass]
78
78
  def hide_interface!
79
79
  Vedeu.bind(:_hide_interface_) do |name|
80
80
  Vedeu::Interface.hide_interface(name)
@@ -89,7 +89,7 @@ module Vedeu
89
89
  # Vedeu.trigger(:_cursor_show_, name)
90
90
  # Vedeu.show_cursor(name)
91
91
  #
92
- # @return [void]
92
+ # @return [TrueClass]
93
93
  def show_cursor!
94
94
  Vedeu.bind(:_show_cursor_) do |name|
95
95
  Vedeu::Cursor.show_cursor(name)
@@ -114,7 +114,7 @@ module Vedeu
114
114
  # Vedeu.trigger(:_show_interface_, name)
115
115
  # Vedeu.show_interface(name)
116
116
  #
117
- # @return [void]
117
+ # @return [TrueClass]
118
118
  def show_interface!
119
119
  Vedeu.bind(:_show_interface_) do |name|
120
120
  Vedeu::Interface.show_interface(name)
@@ -127,7 +127,7 @@ module Vedeu
127
127
  # Vedeu.trigger(:_toggle_cursor_, name)
128
128
  # Vedeu.toggle_cursor(name)
129
129
  #
130
- # @return [void]
130
+ # @return [TrueClass]
131
131
  def toggle_cursor!
132
132
  Vedeu.bind(:_toggle_cursor_) do |name|
133
133
  Vedeu::Cursor.toggle_cursor(name)
@@ -140,7 +140,7 @@ module Vedeu
140
140
  # Vedeu.trigger(:_toggle_group_, name)
141
141
  # Vedeu.toggle_group(name)
142
142
  #
143
- # @return [void]
143
+ # @return [TrueClass]
144
144
  def toggle_group!
145
145
  Vedeu.bind(:_toggle_group_) do |name|
146
146
  Vedeu::Group.toggle_group(name)
@@ -153,7 +153,7 @@ module Vedeu
153
153
  # Vedeu.trigger(:_toggle_interface_, name)
154
154
  # Vedeu.toggle_interface(name)
155
155
  #
156
- # @return [void]
156
+ # @return [TrueClass]
157
157
  def toggle_interface!
158
158
  Vedeu.bind(:_toggle_interface_) do |name|
159
159
  Vedeu::Interface.toggle_interface(name)
@@ -54,7 +54,7 @@ module Vedeu
54
54
  new(value[:colour])
55
55
 
56
56
  elsif value[:background] || value[:foreground]
57
- new(value)
57
+ new(value)
58
58
 
59
59
  else
60
60
  new
data/lib/vedeu/common.rb CHANGED
@@ -10,7 +10,7 @@ module Vedeu
10
10
  # demodulize('Vedeu::DSL::Interface') # => "Interface"
11
11
  #
12
12
  # @param klass [Class|String]
13
- # @return [void]
13
+ # @return [String]
14
14
  def demodulize(klass)
15
15
  klass = klass.to_s
16
16
 
@@ -104,10 +104,15 @@ module Vedeu
104
104
  fail Vedeu::MissingRequired,
105
105
  'Cannot render template without a filename.' unless filename
106
106
 
107
- content = Vedeu::Templating::ViewTemplate.parse(object, filename)
108
- lines = Vedeu::Wordwrap.for(content, options)
107
+ options.merge!(name: name)
109
108
 
110
- new_model = model.member.build(template_attributes(name, lines))
109
+ content = Vedeu::Templating::ViewTemplate.parse(object,
110
+ filename,
111
+ options)
112
+
113
+ # lines = Vedeu::Wordwrap.for(content, options)
114
+
115
+ new_model = model.member.build(template_attributes(name, content))
111
116
 
112
117
  model.add(new_model)
113
118
  end
@@ -25,7 +25,7 @@ module Vedeu
25
25
  # Allows the setting of a border for the interface.
26
26
  #
27
27
  # @example
28
- # interface 'my_interface' do
28
+ # Vedeu.interface 'my_interface' do
29
29
  # border do
30
30
  # # ... see Vedeu::DSL::Border for DSL methods for borders.
31
31
  # end
@@ -51,6 +51,13 @@ module Vedeu
51
51
 
52
52
  # Applies the default border to the interface.
53
53
  #
54
+ # @example
55
+ # Vedeu.interface 'my_interface' do
56
+ # border!
57
+ #
58
+ # # ... some code
59
+ # end
60
+ #
54
61
  # @return [Vedeu::Border]
55
62
  def border!
56
63
  border do
@@ -64,20 +71,23 @@ module Vedeu
64
71
  # to true.
65
72
  #
66
73
  # @example
67
- # interface 'my_interface' do
74
+ # Vedeu.interface 'my_interface' do
68
75
  # cursor true # => show the cursor for this interface
76
+ # # or...
69
77
  # cursor :show # => both of these are equivalent to line above
78
+ # # or...
70
79
  # cursor! #
71
80
  # # ...
72
81
  # end
73
82
  #
74
- # interface 'my_interface' do
83
+ # Vedeu.interface 'my_interface' do
75
84
  # cursor false # => hide the cursor for this interface
85
+ # # or...
76
86
  # cursor nil # => as above
77
87
  # # ...
78
88
  # end
79
89
  #
80
- # view 'my_interface' do
90
+ # Vedeu.view 'my_interface' do
81
91
  # cursor true # => Specify the visibility of the cursor when the view
82
92
  # # ... # is rendered.
83
93
  # end
@@ -103,7 +113,7 @@ module Vedeu
103
113
  # @param value [Fixnum|Float] Time in seconds. (0.5 = 500ms).
104
114
  #
105
115
  # @example
106
- # interface 'my_interface' do
116
+ # Vedeu.interface 'my_interface' do
107
117
  # delay 0.5 # interface will not update more often than every 500ms.
108
118
  # # ...
109
119
  # end
@@ -134,7 +144,7 @@ module Vedeu
134
144
  # Define the geometry for an interface.
135
145
  #
136
146
  # @example
137
- # interface 'my_interface' do
147
+ # Vedeu.interface 'my_interface' do
138
148
  # geometry do
139
149
  # # ... see Vedeu::DSL::Geometry for DSL methods for geometries.
140
150
  # end
@@ -160,7 +170,7 @@ module Vedeu
160
170
  # interfaces at once.
161
171
  #
162
172
  # @example
163
- # interface 'my_interface' do
173
+ # Vedeu.interface 'my_interface' do
164
174
  # group 'main_screen'
165
175
  # # ...
166
176
  # end
@@ -187,13 +197,13 @@ module Vedeu
187
197
  # @param block [Proc]
188
198
  #
189
199
  # @example
190
- # view 'my_interface' do
200
+ # Vedeu.view 'my_interface' do
191
201
  # lines do
192
202
  # # ... see {Vedeu::DSL::Line} and {Vedeu::DSL::Stream}
193
203
  # end
194
204
  # end
195
205
  #
196
- # view 'my_interface' do
206
+ # Vedeu.view 'my_interface' do
197
207
  # line do
198
208
  # # ... see {Vedeu::DSL::Line} and {Vedeu::DSL::Stream}
199
209
  # end
@@ -214,7 +224,7 @@ module Vedeu
214
224
  # @param value [String]
215
225
  #
216
226
  # @example
217
- # interface do
227
+ # Vedeu.interface do
218
228
  # name 'my_interface'
219
229
  # # ...
220
230
  # end
@@ -233,6 +243,13 @@ module Vedeu
233
243
 
234
244
  # Set the interface to visible.
235
245
  #
246
+ # @example
247
+ # Vedeu.interface('my_interface') do
248
+ # show!
249
+ #
250
+ # # ... some code
251
+ # end
252
+ #
236
253
  # @return [void]
237
254
  def show!
238
255
  visible(true)
@@ -240,6 +257,11 @@ module Vedeu
240
257
 
241
258
  # Set the interface to invisible.
242
259
  #
260
+ # @example
261
+ # Vedeu.interface('my_interface') do
262
+ # # ... some code
263
+ # end
264
+ #
243
265
  # @return [void]
244
266
  def hide!
245
267
  visible(false)
@@ -260,21 +282,23 @@ module Vedeu
260
282
  # to true.
261
283
  #
262
284
  # @example
263
- # interface 'my_interface' do
285
+ # Vedeu.interface 'my_interface' do
264
286
  # visible true # => show the interface
287
+ # # or...
265
288
  # show! # => as above
266
- # # ...
289
+ # # ... some code
267
290
  # end
268
291
  #
269
- # interface 'my_interface' do
292
+ # Vedeu.interface 'my_interface' do
270
293
  # visible false # => hide the interface
294
+ # # or...
271
295
  # hide! # => as above
272
- # # ...
296
+ # # ... some code
273
297
  # end
274
298
  #
275
- # view 'my_interface' do
299
+ # Vedeu.view 'my_interface' do
276
300
  # visible false
277
- # # ...
301
+ # # ... some code
278
302
  # end
279
303
  #
280
304
  # @return [void]
@@ -294,7 +318,7 @@ module Vedeu
294
318
  # --2--
295
319
  # --1-- # rendered first
296
320
  #
297
- # interface 'my_interface' do
321
+ # Vedeu.interface 'my_interface' do
298
322
  # zindex 3
299
323
  # # ...
300
324
  # end
@@ -1,5 +1,8 @@
1
1
  module Vedeu
2
2
 
3
+ # Provides a stack trace of a running client application upon exit in a file
4
+ # for further analysis.
5
+ #
3
6
  module Debug
4
7
 
5
8
  extend self
@@ -62,7 +65,8 @@ module Vedeu
62
65
  # - Creates a call tree report compatible with KCachegrind.
63
66
  # RubyProf::CallTreePrinter
64
67
 
65
- # - Uses the other printers to create several reports in one profiling run
68
+ # - Uses the other printers to create several reports in one profiling
69
+ # run
66
70
  # RubyProf::MultiPrinter
67
71
  end
68
72
 
data/lib/vedeu/log/log.rb CHANGED
@@ -184,6 +184,7 @@ module Vedeu
184
184
  config: [:light_yellow, :yellow],
185
185
  create: [:light_green, :green],
186
186
  debug: [:light_red, :red],
187
+ error: [:light_red, :red],
187
188
  drb: [:light_blue, :blue],
188
189
  event: [:light_magenta, :magenta],
189
190
  info: [:white, :default],
@@ -168,14 +168,15 @@ module Vedeu
168
168
  def defaults
169
169
  {
170
170
  client: nil,
171
- colour: nil,
171
+ colour: Vedeu::Colour.coerce(background: :default,
172
+ foreground: :default),
172
173
  delay: 0.0,
173
174
  group: '',
174
175
  lines: [],
175
176
  name: '',
176
177
  parent: nil,
177
178
  repository: Vedeu.interfaces,
178
- style: nil,
179
+ style: :normal,
179
180
  visible: true,
180
181
  zindex: 0,
181
182
  }
data/lib/vedeu/plugins.rb CHANGED
@@ -22,7 +22,7 @@ module Vedeu
22
22
  #
23
23
  # @param name [String]
24
24
  # @param plugin [Vedeu::Plugin]
25
- # @return [void]
25
+ # @return [Array<void>]
26
26
  def register(name, plugin = false)
27
27
  plugins << plugin if plugin && not_loaded?(name)
28
28
  end
@@ -31,11 +31,8 @@ module Vedeu
31
31
  # @return [void]
32
32
  def start
33
33
  configure_log!
34
-
35
34
  client_configuration!
36
-
37
35
  client_application!
38
-
39
36
  client_initialize!
40
37
 
41
38
  Vedeu::Launcher.execute!(argv)
@@ -78,10 +78,11 @@ module Vedeu
78
78
  @exit_code = 0
79
79
 
80
80
  rescue StandardError => uncaught_exception
81
- Vedeu.log_stdout(message: uncaught_exception.message)
81
+ Vedeu.log_stdout(type: :error, message: uncaught_exception.message)
82
82
 
83
83
  if configuration.debug?
84
- Vedeu.log_stdout(message: uncaught_exception.backtrace.join("\n"))
84
+ Vedeu.log_stdout(type: :error,
85
+ message: uncaught_exception.backtrace.join("\n"))
85
86
  end
86
87
  end
87
88
 
@@ -11,24 +11,24 @@ module Vedeu
11
11
  # Registers a controller with the given controller name for the client
12
12
  # application.
13
13
  #
14
- # @param controller_name [Symbol]
14
+ # @param controller [Symbol]
15
15
  # @param klass [String]
16
16
  # @raise [Vedeu::MissingRequired] When the controller name is not given.
17
17
  # @return [void]
18
- def add_controller(controller_name, klass)
19
- unless present?(controller_name)
18
+ def add_controller(controller, klass)
19
+ unless present?(controller)
20
20
  fail Vedeu::MissingRequired,
21
21
  'Cannot store controller without a name attribute.'
22
22
  end
23
23
 
24
24
  Vedeu.log(type: :create,
25
- message: "Adding ':#{controller_name}'")
25
+ message: "Adding ':#{controller}'")
26
26
 
27
- if registered?(controller_name)
28
- storage[controller_name].merge!(klass: klass)
27
+ if registered?(controller)
28
+ storage[controller].merge!(klass: klass)
29
29
 
30
30
  else
31
- storage.store(controller_name, klass: klass, actions: [])
31
+ storage.store(controller, klass: klass, actions: [])
32
32
 
33
33
  end
34
34
 
@@ -38,22 +38,22 @@ module Vedeu
38
38
  # Registers an action to the given controller name for the client
39
39
  # application.
40
40
  #
41
- # @param controller_name [Symbol]
42
- # @param action_name [Symbol]
41
+ # @param controller [Symbol]
42
+ # @param action [Symbol]
43
43
  # @raise [Vedeu::MissingRequired] When the controller name or action name is
44
44
  # not given.
45
45
  # @return [void]
46
- def add_action(controller_name, action_name)
47
- if present?(controller_name) && present?(action_name)
46
+ def add_action(controller, action)
47
+ if present?(controller) && present?(action)
48
48
  Vedeu.log(type: :create,
49
- message: "Adding ':#{action_name}' for ':#{controller_name}'")
49
+ message: "Adding ':#{action}' for ':#{controller}'")
50
50
 
51
- if registered?(controller_name)
52
- storage[controller_name][:actions] << action_name
51
+ if registered?(controller)
52
+ storage[controller][:actions] << action
53
53
 
54
54
  else
55
- add_controller(controller_name, '')
56
- add_action(controller_name, action_name)
55
+ add_controller(controller, '')
56
+ add_action(controller, action)
57
57
 
58
58
  end
59
59
 
@@ -70,30 +70,28 @@ module Vedeu
70
70
  # parameters.
71
71
  #
72
72
  # @example
73
- # Vedeu.goto(controller_name, action_name, args)
73
+ # Vedeu.goto(controller, action, args)
74
74
  #
75
- # @param controller_name [Symbol]
76
- # @param action_name [Symbol]
75
+ # @param controller [Symbol]
76
+ # @param action [Symbol]
77
77
  # @param args [void]
78
78
  # @raise [Vedeu::ModelNotFound] When the controller is not registered.
79
79
  # @return [void]
80
- def goto(controller_name, action_name, **args)
81
- if action_defined?(action_name, controller_name)
82
- Vedeu.log(type: :debug,
83
- message: "Routing: #{controller_name} #{action_name}")
80
+ def goto(controller, action, **args)
81
+ Vedeu.log(type: :debug,
82
+ message: "Routing: #{controller} #{action}")
84
83
 
85
- controller_with(controller_name).send(action_name, args)
86
- end
84
+ route(controller, action, args) if action_defined?(action, controller)
87
85
  end
88
86
  alias_method :action, :goto
89
87
 
90
88
  # Returns a boolean indicating whether the given controller name is already
91
89
  # registered.
92
90
  #
93
- # @param controller_name [Symbol]
91
+ # @param controller [Symbol]
94
92
  # @return [Boolean]
95
- def registered?(controller_name)
96
- storage.key?(controller_name)
93
+ def registered?(controller)
94
+ storage.key?(controller)
97
95
  end
98
96
 
99
97
  # Removes all stored controllers with their respective actions.
@@ -109,43 +107,47 @@ module Vedeu
109
107
  # Returns a boolean indicating whether the given action name is defined for
110
108
  # the given controller.
111
109
  #
112
- # @param action_name [Symbol]
113
- # @param controller_name [Symbol]
110
+ # @param action [Symbol]
111
+ # @param controller [Symbol]
114
112
  # @return [Boolean]
115
- def action_defined?(action_name, controller_name)
116
- if registered?(controller_name)
117
- return true if storage[controller_name][:actions].include?(action_name)
113
+ def action_defined?(action, controller)
114
+ if registered?(controller)
115
+ return true if storage[controller][:actions].include?(action)
118
116
 
119
117
  fail Vedeu::ActionNotFound,
120
- "#{action_name} is not registered for #{controller_name}."
118
+ "#{action} is not registered for #{controller}."
121
119
 
122
120
  else
123
- fail Vedeu::ControllerNotFound, "#{controller_name} is not registered."
121
+ fail Vedeu::ControllerNotFound, "#{controller} is not registered."
124
122
 
125
123
  end
126
124
  end
127
125
 
128
- # Instantiate the given controller by name.
126
+ # Instantiate the given controller by name, the call the action (method)
127
+ # with any given arguments.
129
128
  #
130
- # @param controller_name [Symbol]
129
+ # @param controller [Symbol]
130
+ # @param action [Symbol]
131
+ # @param args [Symbol]
131
132
  # @return [void]
132
- def controller_with(controller_name)
133
- Object.const_get(klass_for(controller_name)).new
133
+ def route(controller, action, **args)
134
+ klass = Object.const_get(klass_for(controller)).new
135
+ klass.send(action, args)
134
136
  end
135
137
 
136
138
  # Fetch the class for the controller by name.
137
139
  #
138
- # @param controller_name [Symbol]
140
+ # @param controller [Symbol]
139
141
  # @raise [Vedeu::MissingRequired] When the given controller name does not
140
142
  # have a class defined.
141
143
  # @return [String]
142
- def klass_for(controller_name)
143
- if registered?(controller_name) && klass_defined?(controller_name)
144
- storage[controller_name][:klass]
144
+ def klass_for(controller)
145
+ if registered?(controller) && klass_defined?(controller)
146
+ storage[controller][:klass]
145
147
 
146
148
  else
147
149
  fail Vedeu::MissingRequired,
148
- "Cannot route to #{controller_name} as no class defined."
150
+ "Cannot route to #{controller} as no class defined."
149
151
 
150
152
  end
151
153
  end
@@ -153,10 +155,10 @@ module Vedeu
153
155
  # Returns a boolean indicating whether the given controller name has a class
154
156
  # defined.
155
157
  #
156
- # @param controller_name [Symbol]
158
+ # @param controller [Symbol]
157
159
  # @return [Boolean]
158
- def klass_defined?(controller_name)
159
- present?(storage[controller_name][:klass])
160
+ def klass_defined?(controller)
161
+ present?(storage[controller][:klass])
160
162
  end
161
163
 
162
164
  # Returns all the stored controllers and their respective actions.