Class: IronNails::View::ViewModelCollection

Inherits:
Core::Collection show all
Defined in:
lib/ironnails/view/collections.rb

Instance Method Summary collapse

Methods inherited from Core::Collection

#[], #each, #initialize, #to_a

Constructor Details

This class inherits a constructor from IronNails::Core::Collection

Instance Method Details

#<<(model) ⇒ Object



74
75
76
77
# File 'lib/ironnails/view/collections.rb', line 74

def <<(model)
  @items << model unless has_viewmodel?(model)
  find_viewmodel(model.__view_model_name_)
end

#find_viewmodel(name) ⇒ Object



70
71
72
# File 'lib/ironnails/view/collections.rb', line 70

def find_viewmodel(name)
  self.find { |vm| vm.__view_model_name_ == name }
end

#has_viewmodel?(view_model) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
65
66
67
68
# File 'lib/ironnails/view/collections.rb', line 62

def has_viewmodel?(view_model)
  if view_model.is_a?(String)
    find_viewmodel(view_model).nil?
  else
    find_viewmodel(view_model.__view_model_name_).nil?
  end
end