class ArrayToAssociationWrapper

Public Instance Methods

collection_without_deferred_save() click to toggle source
# File lib/array_to_association_wrapper.rb, line 68
def collection_without_deferred_save
  @association_owner.send("#{@association_name}_without_deferred_save")
end
defer_association_methods_to(owner, association_name) click to toggle source
# File lib/array_to_association_wrapper.rb, line 3
def defer_association_methods_to(owner, association_name)
  @association_owner = owner
  @association_name = association_name
end
find(*args)
Also aliased as: find_without_deferred_save
find_with_deferred_save(*args) click to toggle source
# File lib/array_to_association_wrapper.rb, line 26
def find_with_deferred_save(*args)
  if @association_owner.present?
    collection_without_deferred_save.send(:find, *args)
  else
    find_without_deferred_save
  end
end
Also aliased as: find
find_without_deferred_save(*args)
Alias for: find
first(*args)
Also aliased as: first_without_deferred_save
first_with_deferred_save(*args) click to toggle source
# File lib/array_to_association_wrapper.rb, line 37
def first_with_deferred_save(*args)
  if @association_owner.present?
    collection_without_deferred_save.send(:first, *args)
  else
    first_without_deferred_save
  end
end
Also aliased as: first
first_without_deferred_save(*args)
Alias for: first
include?(obj)
include_with_deferred_save?(obj) click to toggle source

trick collection_name.include?(obj) If you use a collection of SingleTableInheritance and didn't :select 'type' the include? method will not find any subclassed object.

# File lib/array_to_association_wrapper.rb, line 11
def include_with_deferred_save?(obj)
  if @association_owner.present?
    if detect { |itm| itm == obj || (itm[:id] == obj[:id] && obj.is_a?(itm.class)) }
      return true
    else
      return false
    end
  else
    include_without_deferred_save?(obj)
  end
end
Also aliased as: include?
include_without_deferred_save?(obj)
Alias for: include?
last(*args)
Also aliased as: last_without_deferred_save
last_with_deferred_save(*args) click to toggle source
# File lib/array_to_association_wrapper.rb, line 48
def last_with_deferred_save(*args)
  if @association_owner.present?
    collection_without_deferred_save.send(:last, *args)
  else
    last_without_deferred_save
  end
end
Also aliased as: last
last_without_deferred_save(*args)
Alias for: last