Class: RuGUI::BaseController
- Inherits:
-
BaseObject
- Object
- BaseObject
- RuGUI::BaseController
- Includes:
- InitializeHooks, LogSupport, PropertyObserver, SignalSupport
- Defined in:
- lib/rugui/base_controller.rb
Overview
Base class for all controllers.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#controllers ⇒ Object
Returns the value of attribute controllers.
-
#models ⇒ Object
Returns the value of attribute models.
-
#parent_controller ⇒ Object
Returns the value of attribute parent_controller.
-
#views ⇒ Object
Returns the value of attribute views.
Instance Method Summary collapse
-
#framework_adapter ⇒ Object
Returns the framework_adapter for this class.
-
#initialize(parent_controller = nil) ⇒ BaseController
constructor
A new instance of BaseController.
-
#main_controller ⇒ Object
Returns the main controller instance.
-
#post_registration ⇒ Object
Called after the controller is registered in another one.
-
#register_controller(controller, name = nil) ⇒ Object
Registers a child controller for this controller.
-
#register_model(model, name = nil) ⇒ Object
Registers a model for this controller.
-
#register_view(view, name = nil) ⇒ Object
Registers a view for this controller.
Methods included from InitializeHooks
included, #initialize_with_hooks, update_initialize_method
Methods included from SignalSupport
#autoconnect_declared_signals, included
Methods included from LogSupport
Methods included from PropertyObserver
#named_observable_property_updated, #property_updated
Methods included from FrameworkAdapters::FrameworkAdapterSupport
#framework_adapter_for, included, #load_framework_adapter
Methods inherited from BaseObject
Constructor Details
#initialize(parent_controller = nil) ⇒ BaseController
Returns a new instance of BaseController.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rugui/base_controller.rb', line 15 def initialize(parent_controller = nil) @models = {} @views = {} @controllers = {} if parent_controller.nil? @parent_controller = self else @parent_controller = parent_controller end setup_models setup_views setup_controllers end |
Instance Attribute Details
#controllers ⇒ Object
Returns the value of attribute controllers.
12 13 14 |
# File 'lib/rugui/base_controller.rb', line 12 def controllers @controllers end |
#models ⇒ Object
Returns the value of attribute models.
10 11 12 |
# File 'lib/rugui/base_controller.rb', line 10 def models @models end |
#parent_controller ⇒ Object
Returns the value of attribute parent_controller.
13 14 15 |
# File 'lib/rugui/base_controller.rb', line 13 def parent_controller @parent_controller end |
#views ⇒ Object
Returns the value of attribute views.
11 12 13 |
# File 'lib/rugui/base_controller.rb', line 11 def views @views end |
Instance Method Details
#framework_adapter ⇒ Object
Returns the framework_adapter for this class.
35 36 37 |
# File 'lib/rugui/base_controller.rb', line 35 def framework_adapter framework_adapter_for('BaseController') end |
#main_controller ⇒ Object
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.
101 102 103 |
# File 'lib/rugui/base_controller.rb', line 101 def main_controller @main_controller ||= find_main_controller end |
#post_registration ⇒ Object
Called after the controller is registered in another one.
90 91 |
# File 'lib/rugui/base_controller.rb', line 90 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.
77 78 79 80 81 82 83 84 85 |
# File 'lib/rugui/base_controller.rb', line 77 def register_controller(controller, name = nil) controller = create_instance(controller, self) if controller.is_a?(String) or controller.is_a?(Symbol) name ||= controller.class.to_s.underscore controller.parent_controller = self @controllers[name.to_sym] = controller create_controller_attribute_reader(name) controller.post_registration 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.
45 46 47 48 49 50 51 52 53 |
# File 'lib/rugui/base_controller.rb', line 45 def register_model(model, name = nil) model = create_instance(model) if model.is_a?(String) or model.is_a?(Symbol) name ||= model.class.to_s.underscore model.register_observer(self, name) @models[name.to_sym] = model create_model_attribute_reader(name) model.post_registration(self) 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.
61 62 63 64 65 66 67 68 69 |
# File 'lib/rugui/base_controller.rb', line 61 def register_view(view, name = nil) view = create_instance(view) if view.is_a?(String) or view.is_a?(Symbol) name ||= view.class.to_s.underscore view.register_controller(self) @views[name.to_sym] = view create_view_attribute_reader(name) view.post_registration(self) end |