Module: IronNails::Controller::ViewOperations
- Included in:
- Base
- Defined in:
- lib/ironnails/controller/view_operations.rb
Overview
Encapsulates all the operations that have to do with the view model in controllers.
Instance Attribute Summary collapse
-
#nails_engine ⇒ Object
Returns the value of attribute nails_engine.
Instance Method Summary collapse
- #add_action(name, options, &b) ⇒ Object
-
#copy_vars ⇒ Object
copies the instance variables from the class object to this instance.
-
#init_view_manager ⇒ Object
initializes a new instance of the ViewManager.
-
#instance_variable_copy(var) ⇒ Object
copies an instance variable from the class object to this instance.
- #refresh_instance_variables ⇒ Object
- #refresh_objects ⇒ Object
-
#setup_for_showing_view ⇒ Object
setup the viewmodel for the current objects and command defintions.
- #synchronise_with_view_model ⇒ Object
-
#view_model_name ⇒ Object
gets the name of the view model class.
-
#view_name ⇒ Object
gets the view name for the class that includes this module.
Instance Attribute Details
#nails_engine ⇒ Object
Returns the value of attribute nails_engine.
9 10 11 |
# File 'lib/ironnails/controller/view_operations.rb', line 9 def nails_engine @nails_engine end |
Instance Method Details
#add_action(name, options, &b) ⇒ Object
56 57 58 59 60 |
# File 'lib/ironnails/controller/view_operations.rb', line 56 def add_action(name, , &b) [:action] = b if block_given? cmd_def = { "#{name}".to_sym => } nails_engine.add_command_to_view cmd_def end |
#copy_vars ⇒ Object
copies the instance variables from the class object to this instance
92 93 94 |
# File 'lib/ironnails/controller/view_operations.rb', line 92 def copy_vars self.class.instance_variables.each { |var| instance_variable_copy var } end |
#init_view_manager ⇒ Object
initializes a new instance of the ViewManager
27 28 29 30 31 32 33 34 |
# File 'lib/ironnails/controller/view_operations.rb', line 27 def init_view_manager nails_engine.add_observer :refreshing_view, controller_name do setup_for_showing_view end copy_vars #end end |
#instance_variable_copy(var) ⇒ Object
copies an instance variable from the class object to this instance
84 85 86 87 88 89 |
# File 'lib/ironnails/controller/view_operations.rb', line 84 def instance_variable_copy(var) log_on_error do val = self.class.instance_variable_get var instance_variable_set var, val end end |
#refresh_instance_variables ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/ironnails/controller/view_operations.rb', line 73 def refresh_instance_variables objects.each do |k, v| instance_variable_set "@#{k}", v end view_properties.each do |k, v| val = on_view v[:view], :from => v[:element], :get => v[:property] instance_variable_set "@#{k}", val end end |
#refresh_objects ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ironnails/controller/view_operations.rb', line 62 def refresh_objects instance_variables.each do |var| sym = var.gsub(/@/, "").to_sym if objects.has_key?(sym) val = instance_variable_get(var) objects[sym] = val end end objects end |
#setup_for_showing_view ⇒ Object
setup the viewmodel for the current objects and command defintions
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ironnails/controller/view_operations.rb', line 42 def setup_for_showing_view #log_on_error do objs = ModelCollection.generate_for refresh_objects cmds = @command_builder.generate_for commands cmds.each do |cmd| cmd.add_observer(:reading_input) do synchronise_with_view_model end end nails_engine.initialize_with cmds, objs logger.debug "initialized the view manager", IRONNAILS_FRAMEWORKNAME #end end |
#synchronise_with_view_model ⇒ Object
36 37 38 39 |
# File 'lib/ironnails/controller/view_operations.rb', line 36 def synchronise_with_view_model nails_engine.synchronise_to_controller self refresh_instance_variables end |
#view_model_name ⇒ Object
gets the name of the view model class
17 18 19 |
# File 'lib/ironnails/controller/view_operations.rb', line 17 def view_model_name "#{view_name}_view_model" end |
#view_name ⇒ Object
gets the view name for the class that includes this module
12 13 14 |
# File 'lib/ironnails/controller/view_operations.rb', line 12 def view_name self.class.demodulize.underscore.gsub(/_controller$/, '') end |