Module: Vedeu::Runtime::Router
- Extended by:
- Vedeu::Repositories::Storage, Router
- Includes:
- Common
- Included in:
- Router
- Defined in:
- lib/vedeu/runtime/router.rb
Overview
Stores all client application controllers with their respective actions.
Class Method Summary collapse
-
.absent?(variable) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether a variable is nil or empty.
-
.action_defined?(action, controller) ⇒ Boolean
private
Returns a boolean indicating whether the given action name is defined for the given controller.
-
.add_action(controller, action) ⇒ void
Registers an action to the given controller name for the client application.
-
.add_controller(controller, klass) ⇒ void
Registers a controller with the given controller name for the client application.
-
.become(klass, attributes) ⇒ Class
extended
from Common
private
Converts one class into another.
-
.boolean(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating the value was a boolean.
-
.boolean?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value is a Boolean.
-
.escape?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value is an escape sequence object (e.g. Cells::Escape.).
-
.falsy?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value should be considered false.
-
.goto(controller, action, **args) ⇒ void
(also: #action)
-
.hash?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value is a Hash.
-
.in_memory ⇒ Hash<void>
private
Returns an empty collection ready for the storing of client application controllers and actions.
-
.klass_defined?(controller) ⇒ Boolean
private
Returns a boolean indicating whether the given controller name has a class defined.
-
.klass_for(controller) ⇒ String
private
Fetch the class for the controller by name.
-
.line_model? ⇒ Boolean
extended
from Common
private
Returns a boolean indicating the model is a Views::Line.
-
.numeric?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
-
.present?(variable) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether a variable has a useful value.
-
.registered?(controller) ⇒ Boolean
Returns a boolean indicating whether the given controller name is already registered.
-
.reset! ⇒ void
(also: #reset)
extended
from Vedeu::Repositories::Storage
private
Remove all currently stored data for this repository.
-
.route(controller, action, **args) ⇒ void
private
Instantiate the given controller by name, the call the action (method) with any given arguments.
-
.snake_case(klass) ⇒ String
extended
from Common
private
Converts a class name to a lowercase snake case string.
-
.storage ⇒ void
(also: #all)
extended
from Vedeu::Repositories::Storage
private
Return whole repository; provides raw access to the storage for this repository.
-
.stream_model? ⇒ Boolean
extended
from Common
private
Returns a boolean indicating the model is a Views::Stream.
-
.string?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
-
.truthy?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value should be considered true.
-
.view_model? ⇒ Boolean
extended
from Common
private
Returns a boolean indicating the model is a Views::View.
Instance Method Summary collapse
-
#absent?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable is nil or empty.
-
#action_defined?(action, controller) ⇒ Boolean
private
Returns a boolean indicating whether the given action name is defined for the given controller.
-
#add_action(controller, action) ⇒ void
Registers an action to the given controller name for the client application.
-
#add_controller(controller, klass) ⇒ void
Registers a controller with the given controller name for the client application.
-
#become(klass, attributes) ⇒ Class
included
from Common
private
Converts one class into another.
-
#boolean(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating the value was a boolean.
-
#boolean?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Boolean.
-
#escape?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is an escape sequence object (e.g. Cells::Escape.).
-
#falsy?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value should be considered false.
-
#goto(controller, action, **args) ⇒ void
(also: #action)
-
#hash?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Hash.
-
#in_memory ⇒ Hash<void>
private
Returns an empty collection ready for the storing of client application controllers and actions.
-
#klass_defined?(controller) ⇒ Boolean
private
Returns a boolean indicating whether the given controller name has a class defined.
-
#klass_for(controller) ⇒ String
private
Fetch the class for the controller by name.
-
#line_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::Line.
-
#numeric?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
-
#present?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable has a useful value.
-
#registered?(controller) ⇒ Boolean
Returns a boolean indicating whether the given controller name is already registered.
-
#route(controller, action, **args) ⇒ void
private
Instantiate the given controller by name, the call the action (method) with any given arguments.
-
#snake_case(klass) ⇒ String
included
from Common
private
Converts a class name to a lowercase snake case string.
-
#stream_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::Stream.
-
#string?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
-
#truthy?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value should be considered true.
-
#view_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::View.
Class Method Details
.absent?(variable) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether a variable is nil or empty.
.action_defined?(action, controller) ⇒ Boolean (private)
Returns a boolean indicating whether the given action name is defined for the given controller.
108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/vedeu/runtime/router.rb', line 108 def action_defined?(action, controller) if registered?(controller) return true if storage[controller][:actions].include?(action) fail Vedeu::Error::ActionNotFound, "#{action} is not registered for #{controller}." else fail Vedeu::Error::ControllerNotFound, "#{controller} is not registered." end end |
.add_action(controller, action) ⇒ void
This method returns an undefined value.
Registers an action to the given controller name for the client application.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/vedeu/runtime/router.rb', line 51 def add_action(controller, action) if present?(controller) && present?(action) Vedeu.log(type: :create, message: "Action: ':#{action}' " \ "(for ':#{controller}')") if registered?(controller) storage[controller][:actions] << action else add_controller(controller, '') add_action(controller, action) end storage else fail Vedeu::Error::MissingRequired, 'Cannot store action without a controller or name ' \ 'attribute.' end end |
.add_controller(controller, klass) ⇒ void
This method returns an undefined value.
Registers a controller with the given controller name for the client application.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/vedeu/runtime/router.rb', line 24 def add_controller(controller, klass) unless present?(controller) fail Vedeu::Error::MissingRequired, 'Cannot store controller without a name attribute.' end Vedeu.log(type: :create, message: "Controller: ':#{controller}'") if registered?(controller) storage[controller][:klass] = klass else storage.store(controller, klass: klass, actions: []) end storage end |
.become(klass, attributes) ⇒ Class Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts one class into another.
.boolean(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating the value was a boolean.
.boolean?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value is a Boolean.
.escape?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value is an escape sequence object (e.g. Vedeu::Cells::Escape.)
.falsy?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value should be considered false.
.goto(controller, action, **args) ⇒ void Also known as: action
This method returns an undefined value.
83 84 85 86 87 88 |
# File 'lib/vedeu/runtime/router.rb', line 83 def goto(controller, action, **args) Vedeu.log(type: :debug, message: "Routing: #{controller} #{action}") route(controller, action, args) if action_defined?(action, controller) end |
.hash?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value is a Hash.
.in_memory ⇒ Hash<void> (private)
Returns an empty collection ready for the storing of client application controllers and actions.
163 164 165 |
# File 'lib/vedeu/runtime/router.rb', line 163 def in_memory {} end |
.klass_defined?(controller) ⇒ Boolean (private)
Returns a boolean indicating whether the given controller name has a class defined.
155 156 157 |
# File 'lib/vedeu/runtime/router.rb', line 155 def klass_defined?(controller) present?(storage[controller][:klass]) end |
.klass_for(controller) ⇒ String (private)
Fetch the class for the controller by name.
139 140 141 142 143 144 145 146 147 148 |
# File 'lib/vedeu/runtime/router.rb', line 139 def klass_for(controller) if registered?(controller) && klass_defined?(controller) storage[controller][:klass] else fail Vedeu::Error::MissingRequired, "Cannot route to #{controller} as no class defined." end end |
.line_model? ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating the model is a Views::Line.
.numeric?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value is a Fixnum.
.present?(variable) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether a variable has a useful value.
.registered?(controller) ⇒ Boolean
Returns a boolean indicating whether the given controller name is already registered.
96 97 98 |
# File 'lib/vedeu/runtime/router.rb', line 96 def registered?(controller) storage.key?(controller) end |
.reset! ⇒ void Also known as: reset Originally defined in module Vedeu::Repositories::Storage
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Remove all currently stored data for this repository.
.route(controller, action, **args) ⇒ void (private)
This method returns an undefined value.
Instantiate the given controller by name, the call the action (method) with any given arguments.
129 130 131 132 |
# File 'lib/vedeu/runtime/router.rb', line 129 def route(controller, action, **args) klass = Object.const_get(klass_for(controller)).new(**args) klass.send(action) end |
.snake_case(klass) ⇒ String Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a class name to a lowercase snake case string.
.storage ⇒ void Also known as: all Originally defined in module Vedeu::Repositories::Storage
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Return whole repository; provides raw access to the storage for this repository.
.stream_model? ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating the model is a Views::Stream.
.string?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value is a Fixnum.
.truthy?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value should be considered true.
.view_model? ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating the model is a Views::View.
Instance Method Details
#absent?(variable) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether a variable is nil or empty.
#action_defined?(action, controller) ⇒ Boolean (private)
Returns a boolean indicating whether the given action name is defined for the given controller.
108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/vedeu/runtime/router.rb', line 108 def action_defined?(action, controller) if registered?(controller) return true if storage[controller][:actions].include?(action) fail Vedeu::Error::ActionNotFound, "#{action} is not registered for #{controller}." else fail Vedeu::Error::ControllerNotFound, "#{controller} is not registered." end end |
#add_action(controller, action) ⇒ void
This method returns an undefined value.
Registers an action to the given controller name for the client application.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/vedeu/runtime/router.rb', line 51 def add_action(controller, action) if present?(controller) && present?(action) Vedeu.log(type: :create, message: "Action: ':#{action}' " \ "(for ':#{controller}')") if registered?(controller) storage[controller][:actions] << action else add_controller(controller, '') add_action(controller, action) end storage else fail Vedeu::Error::MissingRequired, 'Cannot store action without a controller or name ' \ 'attribute.' end end |
#add_controller(controller, klass) ⇒ void
This method returns an undefined value.
Registers a controller with the given controller name for the client application.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/vedeu/runtime/router.rb', line 24 def add_controller(controller, klass) unless present?(controller) fail Vedeu::Error::MissingRequired, 'Cannot store controller without a name attribute.' end Vedeu.log(type: :create, message: "Controller: ':#{controller}'") if registered?(controller) storage[controller][:klass] = klass else storage.store(controller, klass: klass, actions: []) end storage end |
#become(klass, attributes) ⇒ Class Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts one class into another.
#boolean(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating the value was a boolean.
#boolean?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value is a Boolean.
#escape?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value is an escape sequence object (e.g. Vedeu::Cells::Escape.)
#falsy?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value should be considered false.
#goto(controller, action, **args) ⇒ void Also known as: action
This method returns an undefined value.
83 84 85 86 87 88 |
# File 'lib/vedeu/runtime/router.rb', line 83 def goto(controller, action, **args) Vedeu.log(type: :debug, message: "Routing: #{controller} #{action}") route(controller, action, args) if action_defined?(action, controller) end |
#hash?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value is a Hash.
#in_memory ⇒ Hash<void> (private)
Returns an empty collection ready for the storing of client application controllers and actions.
163 164 165 |
# File 'lib/vedeu/runtime/router.rb', line 163 def in_memory {} end |
#klass_defined?(controller) ⇒ Boolean (private)
Returns a boolean indicating whether the given controller name has a class defined.
155 156 157 |
# File 'lib/vedeu/runtime/router.rb', line 155 def klass_defined?(controller) present?(storage[controller][:klass]) end |
#klass_for(controller) ⇒ String (private)
Fetch the class for the controller by name.
139 140 141 142 143 144 145 146 147 148 |
# File 'lib/vedeu/runtime/router.rb', line 139 def klass_for(controller) if registered?(controller) && klass_defined?(controller) storage[controller][:klass] else fail Vedeu::Error::MissingRequired, "Cannot route to #{controller} as no class defined." end end |
#line_model? ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating the model is a Views::Line.
#numeric?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value is a Fixnum.
#present?(variable) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether a variable has a useful value.
#registered?(controller) ⇒ Boolean
Returns a boolean indicating whether the given controller name is already registered.
96 97 98 |
# File 'lib/vedeu/runtime/router.rb', line 96 def registered?(controller) storage.key?(controller) end |
#route(controller, action, **args) ⇒ void (private)
This method returns an undefined value.
Instantiate the given controller by name, the call the action (method) with any given arguments.
129 130 131 132 |
# File 'lib/vedeu/runtime/router.rb', line 129 def route(controller, action, **args) klass = Object.const_get(klass_for(controller)).new(**args) klass.send(action) end |
#snake_case(klass) ⇒ String Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a class name to a lowercase snake case string.
#stream_model? ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating the model is a Views::Stream.
#string?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value is a Fixnum.
#truthy?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value should be considered true.
#view_model? ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating the model is a Views::View.