Class: RuGUI::BaseController

Inherits:
BaseObject show all
Includes:
EntityRegistrationSupport, InitializeHooks, LogSupport, PropertyObserver, SignalSupport
Defined in:
lib/rugui/base_controller.rb

Overview

Base class for all controllers.

Direct Known Subclasses

BaseMainController

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from InitializeHooks

included, #initialize_with_hooks, update_initialize_method

Methods included from EntityRegistrationSupport

included

Methods included from SignalSupport

#autoconnect_declared_signals, included

Methods included from LogSupport

included, #logger

Methods included from PropertyObserver

included, #named_observable_property_updated, #property_updated

Methods included from FrameworkAdapters::FrameworkAdapterSupport

#framework_adapter_for, included, #load_framework_adapter

Methods inherited from BaseObject

#inspect

Constructor Details

#initialize(parent_controller = nil) ⇒ BaseController

Returns a new instance of BaseController.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rugui/base_controller.rb', line 17

def initialize(parent_controller = nil)
  @models = {}
  @main_models = {}
  @views = {}
  @controllers = {}

  if parent_controller.nil?
    @parent_controller = self
  else
    @parent_controller = parent_controller
  end

  register_all :model
  setup_models

  register_default_view if should_register_default_view?
  register_all :view
  setup_views

  register_all :controller
  setup_controllers

  register_all :main_model
  setup_main_models
end

Instance Attribute Details

#controllersObject

Returns the value of attribute controllers.



14
15
16
# File 'lib/rugui/base_controller.rb', line 14

def controllers
  @controllers
end

#main_modelsObject

Returns the value of attribute main_models.



12
13
14
# File 'lib/rugui/base_controller.rb', line 12

def main_models
  @main_models
end

#modelsObject

Returns the value of attribute models.



11
12
13
# File 'lib/rugui/base_controller.rb', line 11

def models
  @models
end

#parent_controllerObject

Returns the value of attribute parent_controller.



15
16
17
# File 'lib/rugui/base_controller.rb', line 15

def parent_controller
  @parent_controller
end

#viewsObject

Returns the value of attribute views.



13
14
15
# File 'lib/rugui/base_controller.rb', line 13

def views
  @views
end

Class Method Details

.controllers(*names) ⇒ Object



124
125
126
# File 'lib/rugui/base_controller.rb', line 124

def controllers(*names)
  register(:controller, *names)
end

.main_models(*names) ⇒ Object



116
117
118
# File 'lib/rugui/base_controller.rb', line 116

def main_models(*names)
  register(:main_model, *names)
end

.models(*names) ⇒ Object



112
113
114
# File 'lib/rugui/base_controller.rb', line 112

def models(*names)
  register(:model, *names)
end

.views(*names) ⇒ Object



120
121
122
# File 'lib/rugui/base_controller.rb', line 120

def views(*names)
  register(:view, *names)
end

Instance Method Details

#framework_adapterObject

Returns the framework_adapter for this class.



47
48
49
# File 'lib/rugui/base_controller.rb', line 47

def framework_adapter
  framework_adapter_for('BaseController')
end

#main_controllerObject

Returns the main controller instance.

This is an useful way to quickly access the main controller from any other controller. Since applications may have only one main controller and it is always the ‘root’ of the tree of controllers, this provides indirect access to any other controller in the application.

NOTE: The main controller is cached, so that subsequent calls are faster.



107
108
109
# File 'lib/rugui/base_controller.rb', line 107

def main_controller
  @main_controller ||= find_main_controller
end

#post_registrationObject

Called after the controller is registered in another one.



96
97
# File 'lib/rugui/base_controller.rb', line 96

def post_registration
end

#register_controller(controller, name = nil) ⇒ Object

Registers a child controller for this controller.

If the given controller is a string or symbol, it will be camelized and a new instance of the controller class will be created.



89
90
91
# File 'lib/rugui/base_controller.rb', line 89

def register_controller(controller, name = nil)
  register(:controller, controller, name)
end

#register_main_model(model_name, name = nil) ⇒ Object

Registers a main model for this controller.

Only model names (as string or symbol) should be passed. Optionally a different name may be given. If the main controller doesn’t have a model registered or if this is the main controller a NoMethodError exception will be raised.



69
70
71
# File 'lib/rugui/base_controller.rb', line 69

def register_main_model(model_name, name = nil)
  register(:main_model, model_name, name)
end

#register_model(model, name = nil) ⇒ Object

Registers a model for this controller.

If the given model is a string or symbol, it will be camelized and a new instance of the model class will be created.



57
58
59
# File 'lib/rugui/base_controller.rb', line 57

def register_model(model, name = nil)
  register(:model, model, name)
end

#register_view(view, name = nil) ⇒ Object

Registers a view for this controller.

If the given view is a string or symbol, it will be camelized and a new instance of the view class will be created.



79
80
81
# File 'lib/rugui/base_controller.rb', line 79

def register_view(view, name = nil)
  register(:view, view, name)
end