Module: SugarCRM::AssociationCache

Defined in:
lib/sugarcrm/associations/association_cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#association_cacheObject (readonly)

Returns the value of attribute association_cache.



3
4
5
# File 'lib/sugarcrm/associations/association_cache.rb', line 3

def association_cache
  @association_cache
end

Instance Method Details

#association_cached?(association) ⇒ Boolean

Returns true if an association is cached

Returns:

  • (Boolean)


6
7
8
# File 'lib/sugarcrm/associations/association_cache.rb', line 6

def association_cached?(association)
  @association_cache.symbolize_keys.include? association.to_sym
end

#associations_changed?Boolean

Returns true if an association collection has changed

Returns:

  • (Boolean)


23
24
25
26
27
28
# File 'lib/sugarcrm/associations/association_cache.rb', line 23

def associations_changed?
  @association_cache.values.each do |collection|
    return true if collection.changed?
  end
  false
end

#update_association_cache_for(association, target, action = :add) ⇒ Object

Updates an association cache entry if it’s been initialized



11
12
13
14
15
16
17
18
19
20
# File 'lib/sugarcrm/associations/association_cache.rb', line 11

def update_association_cache_for(association, target, action=:add)
  return unless association_cached? association
  case action
  when :add
    return if @association_cache[association].collection.include? target
    @association_cache[association].push(target) # don't use `<<` because overriden method in AssociationCollection gets called instead
  when :delete      
    @association_cache[association].delete target
  end
end