Module: IronNails::View::ViewModelMixin
- Includes:
- Logging::ClassLogger
- Defined in:
- lib/ironnails/view/view_model.rb
Overview
The base class for view models in an IronNails application.
Instance Method Summary collapse
- #__view_model_name_ ⇒ Object
-
#add_command(cmd) ⇒ Object
configures a command appropriately on the view.
-
#add_model(k, v) ⇒ Object
(also: #set_model)
adds a model for the view in the dictionary.
Methods included from Logging::ClassLogger
Instance Method Details
#__view_model_name_ ⇒ Object
10 11 12 |
# File 'lib/ironnails/view/view_model.rb', line 10 def __view_model_name_ self.class.demodulize.underscore end |
#add_command(cmd) ⇒ Object
configures a command appropriately on the view. for an EventCommand it will pass it to the view and the view will attach the appropriate events for a TimedCommand it will create a timer in the view proxy object for a BehaviorCommand it will add the appropriate delegate command to the Commands dictionary on the ViewModel class
31 32 33 34 35 36 37 38 39 |
# File 'lib/ironnails/view/view_model.rb', line 31 def add_command(cmd) dc = cmd.to_clr_command cmd_name = cmd.name.to_s unless self.respond_to?(cmd_name.to_sym) && self.respond_to?(:"#{cmd_name}=") logger.debug "adding command to the view model #{cmd_name}", IRONNAILS_FRAMEWORKNAME self.class.send :attr_accessor, cmd_name.to_sym end self.send :"#{cmd_name}=", dc end |
#add_model(k, v) ⇒ Object Also known as: set_model
adds a model for the view in the dictionary
15 16 17 18 19 20 21 |
# File 'lib/ironnails/view/view_model.rb', line 15 def add_model(k, v) unless self.respond_to?(k) && self.respond_to?(:"#{k}=") logger.debug "adding object to the view model #{k}", IRONNAILS_FRAMEWORKNAME self.class.send :attr_accessor, k end self.send :"#{k}=", v end |