Module: Core
- Defined in:
- app/core/Core.rb
Overview
Module permettant de gérer les liens entre les vues et les contrôleurs suivant des modèles particuliers
Constant Summary
- ROOT =
Définit le répertoire de la racine
File.(File.dirname(File.dirname(__FILE__))) + "/"
- ROOTPROJECT =
Définit la racine du projet
File.dirname(ROOT) + "/"
- CONTROLLER =
Définit le contrôleur
"Controleur"
- VIEW =
Définit la vue
"Fenetre"
- DEBUG =
Définit le mode debug
false
- DEFAULT_DATABASE_LOG =
Définit le log de la base de données
"log/main.log"
- DEFAULT_ADAPTER =
Définit la base de données
"sqlite3"
- DEFAULT_DATABASE_DIR =
Définit le répertoire de la base de données
"db/"
- DEFAULT_DATABASE_NAME =
Définit le fichier où contiennent les éléments de la base de données
"main.sqlite3"
Class Method Summary collapse
-
.back ⇒ Object
Back to previous window.
-
.changeTo(name, **args) ⇒ Object
Change window.
-
.controllerPath(name) ⇒ Object
Give controller path for controller called.
-
.forceParentInit(o) ⇒ Object
Force children overriding constructor inherited from parent class to run parent constructor.
-
.load(name, **args) ⇒ Object
Load a controller and render its view.
-
.loadController(name) ⇒ Object
Loads a controller.
-
.modelPath(name) ⇒ Object
Give model path for model called.
-
.viewPath(name) ⇒ Object
Give view path for view called.
Class Method Details
.back ⇒ Object
Back to previous window
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/core/Core.rb', line 86 def Core.back() if @previousWindow.length > 1 ## Slice current page @previousWindow.slice!(-1) ## Go back to previous window self.changeTo(@previousWindow.slice!(-1), @args) else puts "Empty stack, you can't back to a non stacked window." end return self end |
.changeTo(name, **args) ⇒ Object
Change window
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/core/Core.rb', line 57 def Core.changeTo(name, **args) ## Prevent some issue with back option ## no more loop possible when caller is ## identical as destination. ## Act like an Ariane's thread we ## can now back on all previous windows. if @previousWindow.slice(-1) != name ## Save caller window @previousWindow << name end @args = args ## Create a new empty window Fenetre::fenetrePrecedente = Fenetre::fenetre.children.clone() Fenetre::viderFenetre load(name, args) return self end |
.controllerPath(name) ⇒ Object
Give controller path for controller called.
128 129 130 |
# File 'app/core/Core.rb', line 128 def Core.controllerPath(name) return ROOT + "controller/" + name + ".rb" end |
.forceParentInit(o) ⇒ Object
Force children overriding constructor inherited from parent class to run parent constructor.
138 139 140 141 142 143 144 145 146 |
# File 'app/core/Core.rb', line 138 def Core.forceParentInit(o) ## Force to call parent method if children override it if o.method(:initialize).owner != o.class.name o.method(:initialize).super_method.call o.method(:initialize).call end end |
.load(name, **args) ⇒ Object
Load a controller and render its view
41 42 43 44 45 46 47 48 |
# File 'app/core/Core.rb', line 41 def Core.load(name, **args) controller = loadController(name) controller.render(name, args) return self end |
.loadController(name) ⇒ Object
Loads a controller.
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'app/core/Core.rb', line 155 def Core.loadController(name) name = name + CONTROLLER ## Define file path for controller filePath = self.controllerPath(name) begin require filePath rescue LoadError if DEBUG puts "Controller: " + name + " not found in " + ROOT + "controller" end exit(1) end ## Will retrieve class constant name for dynamic instanciation controllerName = Object.const_get(name) controller = controllerName.new() return controller end |