Class: IronNails::Core::NailsEngine
- Inherits:
-
Object
- Object
- IronNails::Core::NailsEngine
- Defined in:
- lib/ironnails/nails_engine.rb
Overview
This could be viewed as the life support for the Nails framework It serves as the glue between the different components. One of its main functions is to manage communication between the controller, view model and view.
Instance Attribute Summary collapse
-
#registry ⇒ Object
Stores the registered components and does lookup on them.
Attributes included from ViewModelOperations
Attributes included from ViewModelCommandOperations
Attributes included from ViewModelObjectOperations
Instance Method Summary collapse
- #add_command_to_view(commands) ⇒ Object
-
#configure_events(model, view) ⇒ Object
processes the command queue.
-
#configure_models(model) ⇒ Object
configures the properties for the view model.
-
#configure_view(view) ⇒ Object
configures the view.
-
#configured? ⇒ Boolean
returns whether this view needs configuration or not.
-
#initialize ⇒ NailsEngine
constructor
A new instance of NailsEngine.
- #initialize_with(command_definitions, models) ⇒ Object
-
#refresh_view(view) ⇒ Object
refreshes the data for the view.
- #register_controller(controller) ⇒ Object
- #set_viewmodel_for(controller, key, value) ⇒ Object
- #show_initial_window(controller) {|registry.view_for(controller).instance| ... } ⇒ Object
- #synchronise_to_controller(controller) ⇒ Object
-
#synchronise_with_controller ⇒ Object
synchronises the data in the viewmodel with the controller.
Methods included from ViewModelOperations
#init_viewmodel_operations, #register_viewmodel_for
Methods included from ViewModelCommandOperations
#add_command_to_queue, #init_command_operations
Methods included from ViewModelObjectOperations
#add_model_to_queue_on, #init_object_operations
Methods included from ViewOperations
#build_view, #find_view, #from_view, #init_view_operations, #on_ui_thread, #on_view, #play_storyboard, #register_child_view, #register_view_for, #stop_storyboard, #to_update_ui_after
Methods included from ControllerObservable
#add_observer, #count_observers, #delete_observer, #delete_observers, #notify_observers
Methods included from Logging::ClassLogger
Constructor Details
#initialize ⇒ NailsEngine
Returns a new instance of NailsEngine.
363 364 365 366 367 |
# File 'lib/ironnails/nails_engine.rb', line 363 def initialize @configured, @registry = false, ComponentRegistry.new init_viewmodel_operations init_view_operations end |
Instance Attribute Details
#registry ⇒ Object
Stores the registered components and does lookup on them
282 283 284 |
# File 'lib/ironnails/nails_engine.rb', line 282 def registry @registry end |
Instance Method Details
#add_command_to_view(commands) ⇒ Object
335 336 337 |
# File 'lib/ironnails/nails_engine.rb', line 335 def add_command_to_view(commands) add_commands_to_queue commands end |
#configure_events(model, view) ⇒ Object
processes the command queue.
299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/ironnails/nails_engine.rb', line 299 def configure_events(model, view) command_queue.each do |cmd| case when cmd.is_a?(EventCommand) view.add_command(cmd) when cmd.is_a?(TimedCommand) view.add_timer(cmd) view.proxy.start_timer(cmd) when cmd.is_a?(BehaviorCommand) model.add_command cmd end unless cmd.attached? end end |
#configure_models(model) ⇒ Object
configures the properties for the view model
290 291 292 293 294 295 296 |
# File 'lib/ironnails/nails_engine.rb', line 290 def configure_models(model) model_queue.each do |o| o.each do |k, v| model.add_model k, v end unless o.nil? end end |
#configure_view(view) ⇒ Object
configures the view
314 315 316 317 318 319 320 |
# File 'lib/ironnails/nails_engine.rb', line 314 def configure_view(view) model = registry.viewmodel_for view.controller configure_models(model) configure_events(model, view) view.data_context = model unless view.has_datacontext? && !view.sets_datacontext? @configured = true end |
#configured? ⇒ Boolean
returns whether this view needs configuration or not
359 360 361 |
# File 'lib/ironnails/nails_engine.rb', line 359 def configured? !!@configured end |
#initialize_with(command_definitions, models) ⇒ Object
387 388 389 390 391 392 |
# File 'lib/ironnails/nails_engine.rb', line 387 def initialize_with(command_definitions, models) add_commands_to_queue command_definitions add_models_to_queue_on models logger.debug "Added commands to queue on view manager.", IRONNAILS_FRAMEWORKNAME logger.debug "Added models to queue on view manager.", IRONNAILS_FRAMEWORKNAME end |
#refresh_view(view) ⇒ Object
refreshes the data for the view.
323 324 325 326 327 328 |
# File 'lib/ironnails/nails_engine.rb', line 323 def refresh_view(view) notify_observers :refreshing_view, view.controller, self, view view.configure view.proxy.refresh @configured = true end |
#register_controller(controller) ⇒ Object
369 370 371 372 373 374 375 376 |
# File 'lib/ironnails/nails_engine.rb', line 369 def register_controller(controller) logger.debug "registering controller #{controller.controller_name}", IRONNAILS_FRAMEWORKNAME registry.register(controller) register_viewmodel_for controller register_view_for controller controller.nails_engine = self logger.debug "controller #{controller.controller_name} registered", IRONNAILS_FRAMEWORKNAME end |
#set_viewmodel_for(controller, key, value) ⇒ Object
284 285 286 287 |
# File 'lib/ironnails/nails_engine.rb', line 284 def set_viewmodel_for(controller, key, value) model = registry.viewmodel_for controller model.set_model key, value end |
#show_initial_window(controller) {|registry.view_for(controller).instance| ... } ⇒ Object
378 379 380 381 382 383 384 385 |
# File 'lib/ironnails/nails_engine.rb', line 378 def show_initial_window(controller) logger.debug "setting up controller", IRONNAILS_FRAMEWORKNAME #controller.setup_for_showing_view registry.view_for(controller).load controller.default_action if controller.respond_to? :default_action controller.setup_for_showing_view yield registry.view_for(controller).instance if block_given? end |
#synchronise_to_controller(controller) ⇒ Object
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
# File 'lib/ironnails/nails_engine.rb', line 339 def synchronise_to_controller(controller) objects = controller.instance_variable_get "@objects" #model = registry.viewmodel_for controller #.objects.collect { |kvp| kvp.key.to_s.underscore.to_sym } vw = registry.view_for controller model = vw.proxy.data_context objects.each do |k, v| if model.respond_to?(k.to_sym) val = model.send k.to_sym objects[k] = val controller.instance_variable_set "@#{k}", val end end view_properties = controller.instance_variable_get "@view_properties" view_properties.each do |k, v| val = from_view controller, (v[:view]||controller.view_name), v[:element], v[:property] instance_variable_set "@#{k}", val end end |
#synchronise_with_controller ⇒ Object
synchronises the data in the viewmodel with the controller
331 332 333 |
# File 'lib/ironnails/nails_engine.rb', line 331 def synchronise_with_controller notify_observers :reading_input, self, view end |