Module: IronNails::Core::ViewModelOperations

Includes:
ViewModelCommandOperations, ViewModelObjectOperations
Included in:
NailsEngine
Defined in:
lib/ironnails/nails_engine.rb

Instance Attribute Summary collapse

Attributes included from ViewModelCommandOperations

#command_queue

Attributes included from ViewModelObjectOperations

#model_queue

Instance Method Summary collapse

Methods included from ViewModelCommandOperations

#add_command_to_queue, #init_command_operations

Methods included from ViewModelObjectOperations

#add_model_to_queue_on, #init_object_operations

Instance Attribute Details

#view_modelsObject

gets the view model instance to manipulate with this builder



193
194
195
# File 'lib/ironnails/nails_engine.rb', line 193

def view_models
  @view_models
end

Instance Method Details

#init_viewmodel_operationsObject



198
199
200
201
202
# File 'lib/ironnails/nails_engine.rb', line 198

def init_viewmodel_operations
  init_object_operations
  init_command_operations
  @view_models = {}
end

#register_viewmodel_for(controller) ⇒ Object



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/ironnails/nails_engine.rb', line 204

def register_viewmodel_for(controller)
  vm_class_name = controller.view_model_name.camelize
  Object.const_set vm_class_name, Class.new unless Object.const_defined? vm_class_name

  # TODO: There is an issue with namespacing and CLR classes, they aren't registered as constants with
  #       IronRuby. This makes it hard to namespace viewmodels. If the namespace is included everything 
  #       should work as normally. Will revisit this later to properly fix it.        
  vm_name = controller.view_model_name
  klass = Object.const_get vm_class_name
  klass.send :include, IronNails::Models::Databinding
  klass.send :include, IronNails::View::ViewModelMixin
  key = vm_name.to_sym
  view_models[key] = klass.new if view_models[key].nil?
  registry.register_viewmodel_for controller, view_models[key]
  view_models[key]
end