vedeu 0.4.61 → 0.4.62
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vedeu/all.rb +2 -0
- data/lib/vedeu/application/controller.rb +41 -9
- data/lib/vedeu/bindings.rb +4 -1
- data/lib/vedeu/bindings/application.rb +36 -0
- data/lib/vedeu/bootstrap.rb +6 -1
- data/lib/vedeu/cli/generator/templates/application/app/controllers/name.erb +10 -4
- data/lib/vedeu/colours/colour.rb +6 -9
- data/lib/vedeu/repositories/model.rb +1 -1
- data/lib/vedeu/router.rb +117 -0
- data/lib/vedeu/version.rb +1 -1
- data/test/lib/vedeu/application/application_controller_test.rb +1 -1
- data/test/lib/vedeu/application/application_helper_test.rb +1 -1
- data/test/lib/vedeu/application/controller_test.rb +35 -11
- data/test/lib/vedeu/application/helper_test.rb +1 -1
- data/test/lib/vedeu/bindings/application_test.rb +38 -0
- data/test/lib/vedeu/bindings_test.rb +45 -0
- data/test/lib/vedeu/borders/render_border_test.rb +1 -1
- data/test/lib/vedeu/buffers/buffer_test.rb +1 -1
- data/test/lib/vedeu/buffers/display_buffer_test.rb +2 -2
- data/test/lib/vedeu/cli/generator/application_test.rb +1 -1
- data/test/lib/vedeu/cli/generator/helpers_test.rb +1 -1
- data/test/lib/vedeu/colours/colour_test.rb +9 -1
- data/test/lib/vedeu/configuration/api_test.rb +3 -3
- data/test/lib/vedeu/cursor/move_test.rb +5 -5
- data/test/lib/vedeu/cursor/refresh_cursor_test.rb +4 -0
- data/test/lib/vedeu/distributed/client_test.rb +4 -4
- data/test/lib/vedeu/distributed/server_test.rb +9 -9
- data/test/lib/vedeu/dsl/use_test.rb +4 -4
- data/test/lib/vedeu/launcher_test.rb +2 -2
- data/test/lib/vedeu/main_loop_test.rb +2 -2
- data/test/lib/vedeu/output/refresh_group_test.rb +1 -1
- data/test/lib/vedeu/output/refresh_test.rb +1 -1
- data/test/lib/vedeu/output/renderers/html_test.rb +1 -1
- data/test/lib/vedeu/output/renderers/renderer_options_test.rb +1 -1
- data/test/lib/vedeu/output/renderers_test.rb +2 -2
- data/test/lib/vedeu/output/text_test.rb +2 -2
- data/test/lib/vedeu/plugins/plugin_test.rb +1 -1
- data/test/lib/vedeu/plugins_test.rb +2 -2
- data/test/lib/vedeu/repositories/collection_test.rb +1 -1
- data/test/lib/vedeu/repositories/model_test.rb +18 -3
- data/test/lib/vedeu/{repositories/all_test.rb → repositories_test.rb} +0 -0
- data/test/lib/vedeu/router_test.rb +192 -0
- data/test/lib/vedeu/traps_test.rb +1 -1
- data/test/lib/vedeu_test.rb +1 -1
- data/test/support/coverage.rb +42 -0
- data/vedeu.gemspec +2 -2
- metadata +14 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30927938a72729c5f3bae9a255a5c8b7602360f9
|
4
|
+
data.tar.gz: eeb3240c0d98fd5450ddf9f4a9cdf5f5e81ac1b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 645204564d7353b20bd33141221af4a2fa1bca84da5990a4a0280041b304985ce5391809239fd3e08235deab9f87933ea38ead859e4653a494a2e70d49be64c4
|
7
|
+
data.tar.gz: 04ae7389a57c38d513a7f7a8f2af5d1910d8f5fe4881668453a6d2b7eb426450d997c0c7b2c6e938cd50d6c446f8c08f0f6b0bd168b4ea14e1fbc9c302f1b67d
|
data/lib/vedeu/all.rb
CHANGED
@@ -7,6 +7,7 @@ require 'vedeu/debug'
|
|
7
7
|
require 'vedeu/traps'
|
8
8
|
require 'vedeu/common'
|
9
9
|
require 'vedeu/terminal_mode'
|
10
|
+
require 'vedeu/router'
|
10
11
|
|
11
12
|
require 'vedeu/configuration/cli'
|
12
13
|
require 'vedeu/configuration/api'
|
@@ -172,6 +173,7 @@ require 'vedeu/output/wordwrap'
|
|
172
173
|
|
173
174
|
require 'vedeu/api'
|
174
175
|
|
176
|
+
require 'vedeu/bindings/application'
|
175
177
|
require 'vedeu/bindings/drb'
|
176
178
|
require 'vedeu/bindings/menus'
|
177
179
|
require 'vedeu/bindings/movement'
|
@@ -5,26 +5,58 @@ module Vedeu
|
|
5
5
|
module Controller
|
6
6
|
|
7
7
|
# When included, provide these methods as class methods.
|
8
|
+
#
|
8
9
|
module ClassMethods
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
attr_accessor :controller_name
|
12
|
+
|
13
|
+
# Specifying the controller name in your controller provides Vedeu with
|
14
|
+
# the means to route requests to different parts of your application.
|
12
15
|
#
|
13
16
|
# @example
|
14
17
|
# class YourController
|
18
|
+
#
|
19
|
+
# controller :your_controller
|
20
|
+
# # or...
|
15
21
|
# controller_name :your_controller
|
16
|
-
#
|
22
|
+
#
|
23
|
+
# # ... some code
|
24
|
+
#
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# @param controller_name [Symbol] The name of the controller.
|
28
|
+
# @return [void]
|
29
|
+
def controller(controller_name = nil)
|
30
|
+
@controller_name = controller_name
|
31
|
+
|
32
|
+
Vedeu::Router.add_controller(controller_name, ancestors.first.to_s)
|
33
|
+
end
|
34
|
+
alias_method :controller_name, :controller
|
35
|
+
|
36
|
+
# Specifying the action names in your controller provides Vedeu with the
|
37
|
+
# means to route requests to different parts of your application.
|
38
|
+
#
|
39
|
+
# @example
|
40
|
+
# class YourController
|
41
|
+
#
|
42
|
+
# controller :your_controller
|
43
|
+
#
|
44
|
+
# action :show
|
45
|
+
# # or...
|
46
|
+
# action_name :show
|
47
|
+
#
|
48
|
+
# # ... some code
|
49
|
+
#
|
17
50
|
# end
|
18
51
|
#
|
19
|
-
# Vedeu.trigger(:
|
20
|
-
# # trigger.
|
52
|
+
# Vedeu.trigger(:_action_, :your_controller, :show, { some: :args })
|
21
53
|
#
|
22
|
-
# @param
|
54
|
+
# @param action_name [Symbol] THe name of the action.
|
23
55
|
# @return [void]
|
24
|
-
|
25
|
-
|
26
|
-
Vedeu.bind("show_#{name}".to_sym) { new }
|
56
|
+
def action(action_name = nil)
|
57
|
+
Vedeu::Router.add_action(@controller_name, action_name)
|
27
58
|
end
|
59
|
+
alias_method :action_name, :action
|
28
60
|
|
29
61
|
end # ClassMethods
|
30
62
|
|
data/lib/vedeu/bindings.rb
CHANGED
@@ -9,10 +9,13 @@ module Vedeu
|
|
9
9
|
#
|
10
10
|
module Bindings
|
11
11
|
|
12
|
+
extend self
|
13
|
+
|
12
14
|
# Setup events for running Vedeu. This method is called by Vedeu.
|
13
15
|
#
|
14
16
|
# @return [void]
|
15
|
-
def
|
17
|
+
def setup!
|
18
|
+
Vedeu::Bindings::Application.setup!
|
16
19
|
Vedeu::Bindings::Visibility.setup!
|
17
20
|
Vedeu::Bindings::Movement.setup!
|
18
21
|
Vedeu::Bindings::Menus.setup!
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Vedeu
|
2
|
+
|
3
|
+
module Bindings
|
4
|
+
|
5
|
+
# System events relating to movement of cursors or interfaces.
|
6
|
+
#
|
7
|
+
# :nocov:
|
8
|
+
module Application
|
9
|
+
|
10
|
+
extend self
|
11
|
+
|
12
|
+
# Setup events relating to client applications. This method is called by
|
13
|
+
# Vedeu.
|
14
|
+
#
|
15
|
+
# @return [void]
|
16
|
+
def setup!
|
17
|
+
action!
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
# @example
|
23
|
+
# Vedeu.trigger(:_action_, :your_controller, :some_action, { id: 7 })
|
24
|
+
#
|
25
|
+
# @return [void]
|
26
|
+
def action!
|
27
|
+
Vedeu.bind(:_action_) do |controller, action, **args|
|
28
|
+
Vedeu::Router.goto(controller, action, **args)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end # Application
|
33
|
+
|
34
|
+
end # Bindings
|
35
|
+
|
36
|
+
end # Vedeu
|
data/lib/vedeu/bootstrap.rb
CHANGED
@@ -82,7 +82,7 @@ module Vedeu
|
|
82
82
|
|
83
83
|
# @return [void]
|
84
84
|
def client_initialize!
|
85
|
-
entry_point ||
|
85
|
+
entry_point || root
|
86
86
|
end
|
87
87
|
|
88
88
|
# Load each of the loadable files.
|
@@ -113,6 +113,11 @@ module Vedeu
|
|
113
113
|
end unless Vedeu::Configuration.log?
|
114
114
|
end
|
115
115
|
|
116
|
+
# @return [Class]
|
117
|
+
def root
|
118
|
+
Object.const_get(Vedeu::Configuration.root) if Vedeu::Configuration.root
|
119
|
+
end
|
120
|
+
|
116
121
|
end # Bootstrap
|
117
122
|
|
118
123
|
end # Vedeu
|
@@ -5,17 +5,23 @@ module <%= object.app_name %>
|
|
5
5
|
|
6
6
|
class <%= object.name_as_class %>Controller < <%= object.app_name -%>::ApplicationController
|
7
7
|
|
8
|
-
|
8
|
+
controller :<%= object.name %>
|
9
|
+
action :list
|
10
|
+
action :show
|
11
|
+
# add more actions and implement or remove existing actions
|
9
12
|
|
10
13
|
def initialize
|
11
|
-
<%= object.app_name %>::<%= object.name_as_class %>View.render(*args)
|
12
14
|
end
|
13
15
|
|
14
|
-
|
16
|
+
def list
|
17
|
+
end
|
15
18
|
|
16
|
-
def args
|
19
|
+
def show(*args)
|
20
|
+
<%= object.app_name %>::<%= object.name_as_class %>View.render(*args)
|
17
21
|
end
|
18
22
|
|
23
|
+
private
|
24
|
+
|
19
25
|
def object
|
20
26
|
nil
|
21
27
|
end
|
data/lib/vedeu/colours/colour.rb
CHANGED
@@ -40,19 +40,16 @@ module Vedeu
|
|
40
40
|
# @return [Vedeu::Foreground]
|
41
41
|
attr_reader :foreground
|
42
42
|
|
43
|
-
# @param value [Vedeu::Colour|
|
43
|
+
# @param value [Vedeu::Colour|Hash<Symbol => void>]
|
44
44
|
# @return [Object]
|
45
45
|
def self.coerce(value)
|
46
|
-
return value if value.is_a?(
|
47
|
-
return new
|
46
|
+
return value if value.is_a?(Vedeu::Colour)
|
47
|
+
return new unless value.is_a?(Hash)
|
48
48
|
|
49
|
-
if value
|
50
|
-
value[:colour]
|
49
|
+
if value.key?(:colour)
|
50
|
+
coerce(value[:colour])
|
51
51
|
|
52
|
-
elsif value
|
53
|
-
new(value[:colour])
|
54
|
-
|
55
|
-
elsif value[:background] || value[:foreground]
|
52
|
+
elsif value.key?(:background) || value.key?(:foreground)
|
56
53
|
new(value)
|
57
54
|
|
58
55
|
else
|
data/lib/vedeu/router.rb
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
module Vedeu
|
2
|
+
|
3
|
+
# Stores all client application controllers with their respective actions.
|
4
|
+
#
|
5
|
+
module Router
|
6
|
+
|
7
|
+
include Vedeu::Common
|
8
|
+
|
9
|
+
extend self
|
10
|
+
|
11
|
+
# @param controller_name [Symbol]
|
12
|
+
# @param klass [String]
|
13
|
+
# @return [void]
|
14
|
+
def add_controller(controller_name, klass)
|
15
|
+
unless present?(controller_name)
|
16
|
+
fail Vedeu::MissingRequired,
|
17
|
+
'Cannot store controller without a name attribute.'
|
18
|
+
end
|
19
|
+
|
20
|
+
if registered?(controller_name)
|
21
|
+
storage[controller_name].merge!(klass: klass)
|
22
|
+
|
23
|
+
else
|
24
|
+
storage.store(controller_name, klass: klass, actions: [])
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
storage
|
29
|
+
end
|
30
|
+
|
31
|
+
# @param controller_name [Symbol]
|
32
|
+
# @param action_name [Symbol]
|
33
|
+
# @return [void]
|
34
|
+
def add_action(controller_name, action_name)
|
35
|
+
if present?(controller_name) && present?(action_name)
|
36
|
+
if registered?(controller_name)
|
37
|
+
storage[controller_name][:actions] << action_name
|
38
|
+
|
39
|
+
else
|
40
|
+
add_controller(controller_name, '')
|
41
|
+
add_action(controller_name, action_name)
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
storage
|
46
|
+
|
47
|
+
else
|
48
|
+
fail Vedeu::MissingRequired,
|
49
|
+
'Cannot store action without a controller or name attribute.'
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# @param controller_name [Symbol]
|
55
|
+
# @param action_name [Symbol]
|
56
|
+
# @param args [void]
|
57
|
+
# @return [void]
|
58
|
+
def goto(controller_name, action_name, **args)
|
59
|
+
unless registered?(controller_name)
|
60
|
+
fail Vedeu::ModelNotFound, "#{controller_name} is not registered."
|
61
|
+
end
|
62
|
+
|
63
|
+
controller_with(controller_name).send(action_name, args)
|
64
|
+
end
|
65
|
+
|
66
|
+
# @param controller_name [Symbol]
|
67
|
+
# @return [Boolean]
|
68
|
+
def registered?(controller_name)
|
69
|
+
storage.key?(controller_name)
|
70
|
+
end
|
71
|
+
|
72
|
+
# @return [Hash<void>]
|
73
|
+
def reset!
|
74
|
+
@storage = in_memory
|
75
|
+
end
|
76
|
+
alias_method :reset, :reset!
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
# @param controller_name [Symbol]
|
81
|
+
# @return [void]
|
82
|
+
def controller_with(controller_name)
|
83
|
+
Object.const_get(klass_for(controller_name)).new
|
84
|
+
end
|
85
|
+
|
86
|
+
# @param controller_name [Symbol]
|
87
|
+
# @return [String]
|
88
|
+
def klass_for(controller_name)
|
89
|
+
if registered?(controller_name) && klass_defined?(controller_name)
|
90
|
+
storage[controller_name][:klass]
|
91
|
+
|
92
|
+
else
|
93
|
+
fail Vedeu::MissingRequired,
|
94
|
+
"Cannot route to #{controller_name} as no class defined."
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# @param controller_name [Symbol]
|
100
|
+
# @return [Boolean]
|
101
|
+
def klass_defined?(controller_name)
|
102
|
+
present?(storage[controller_name][:klass])
|
103
|
+
end
|
104
|
+
|
105
|
+
# @return [Hash<Symbol => Hash<Symbol => String|Array<Symbol>>>]
|
106
|
+
def storage
|
107
|
+
@storage ||= in_memory
|
108
|
+
end
|
109
|
+
|
110
|
+
# @return [Hash<void>]
|
111
|
+
def in_memory
|
112
|
+
{}
|
113
|
+
end
|
114
|
+
|
115
|
+
end # Router
|
116
|
+
|
117
|
+
end # Vedeu
|
data/lib/vedeu/version.rb
CHANGED
@@ -2,27 +2,51 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module Vedeu
|
4
4
|
|
5
|
-
class
|
5
|
+
class ControllerTestKlass
|
6
6
|
|
7
7
|
include Vedeu::Controller
|
8
8
|
|
9
|
+
controller :some_controller
|
10
|
+
action :some_action
|
11
|
+
|
9
12
|
end # ControllerTestClass
|
10
13
|
|
11
14
|
describe Controller do
|
12
15
|
|
13
|
-
let(:described) { Vedeu::
|
14
|
-
|
16
|
+
let(:described) { Vedeu::Controller }
|
17
|
+
|
18
|
+
let(:described_model) { Vedeu::ControllerTestKlass }
|
19
|
+
let(:instance_model) { described.new }
|
20
|
+
|
21
|
+
describe 'ClassMethods' do
|
22
|
+
let(:described) { Vedeu::Controller::ClassMethods }
|
23
|
+
|
24
|
+
it { described_model.must_respond_to(:controller_name) }
|
25
|
+
it { described_model.must_respond_to(:action_name) }
|
26
|
+
it { described_model.must_respond_to(:controller) }
|
27
|
+
it { described_model.must_respond_to(:action) }
|
28
|
+
|
29
|
+
describe '.controller' do
|
30
|
+
subject { described_model.controller(:some_controller) }
|
31
|
+
|
32
|
+
it {
|
33
|
+
Vedeu::Router.expects(:add_controller).
|
34
|
+
with(:some_controller, 'Vedeu::ControllerTestKlass')
|
35
|
+
subject
|
36
|
+
}
|
37
|
+
end
|
15
38
|
|
16
|
-
|
17
|
-
|
39
|
+
describe '.action' do
|
40
|
+
subject { described_model.action(:some_action) }
|
18
41
|
|
19
|
-
|
42
|
+
it {
|
43
|
+
Vedeu::Router.expects(:add_action).
|
44
|
+
with(:some_controller, :some_action)
|
45
|
+
subject
|
46
|
+
}
|
47
|
+
end
|
20
48
|
|
21
|
-
|
22
|
-
Vedeu.expects(:bind).with(:show_vedeu_controller_test)
|
23
|
-
subject
|
24
|
-
}
|
25
|
-
end
|
49
|
+
end # ClassMethods
|
26
50
|
|
27
51
|
end # Controller
|
28
52
|
|