class FormObj::Form::Array
Public Instance Methods
mark_as_persisted()
click to toggle source
# File lib/form_obj/form/array.rb, line 8 def mark_as_persisted each(&:mark_as_persisted) end
mark_for_destruction()
click to toggle source
# File lib/form_obj/form/array.rb, line 12 def mark_for_destruction each(&:mark_for_destruction) end
marked_for_destruction()
click to toggle source
# File lib/form_obj/form/array.rb, line 16 def marked_for_destruction select(&:marked_for_destruction?) end
persisted?()
click to toggle source
# File lib/form_obj/form/array.rb, line 4 def persisted? empty? || all?(&:persisted?) end
Private Instance Methods
define_items_for_CUD(items)
click to toggle source
Should return hash with 3 keys: :create, :update, :destroy In default implementation: :create - array of hashes of new attribute values :update - hash where key is the item to update and value is a hash of new attribute values :destroy - array of items to be destroyed
# File lib/form_obj/form/array.rb, line 27 def define_items_for_CUD(items) to_be_created = [] to_be_updated = {} to_be_destroyed = [] items.each do |item_hash| item_hash = HashWithIndifferentAccess.new(item_hash) _destroy = item_hash.delete(:_destroy) item = find_by_primary_key(primary_key(item_hash)) if item if _destroy to_be_destroyed << item else to_be_updated[item] = item_hash end elsif !_destroy to_be_created << item_hash end end { create: to_be_created, update: to_be_updated, destroy: to_be_destroyed } end
destroy_items(items)
click to toggle source
items - array of items to be destroyed
# File lib/form_obj/form/array.rb, line 55 def destroy_items(items) items.each(&:mark_for_destruction) end
resort_items_after_CUD!(items)
click to toggle source
Do not do resort since update_attributes parameter may have not full list of items
# File lib/form_obj/form/array.rb, line 51 def resort_items_after_CUD!(items) end