Module: Card::Set::Abstract::SolidCache::ClassMethods

Defined in:
tmpsets/set/mod008-solid_cache/abstract/solid_cache.rb

Instance Method Summary collapse

Instance Method Details

#cache_expire_trigger(set_of_changed_card, args = {}, &block) ⇒ Object

Same as 'cache_update_trigger' but expires instead of updates the outdated solid caches



49
50
51
52
53
# File 'tmpsets/set/mod008-solid_cache/abstract/solid_cache.rb', line 49

def cache_expire_trigger set_of_changed_card, args={}, &block
  define_event_to_update_expired_cached_cards(
    set_of_changed_card, args, :expire_solid_cache, &block
  )
end

#cache_update_trigger(set_of_changed_card, args = {}) { ... } ⇒ Object

If a card of the set given by 'set_of_changed_card' is updated the given block is executed. It is supposed to return an array of cards whose solid caches are expired because of the update.

Parameters:

  • set_of_changed_card (set constant)

    a set of cards that triggers a cache update

  • args (Hash) (defaults to: {})

    a customizable set of options

Options Hash (args):

  • :on (Symbol, Array of symbols)

    the action(s) (:create, :update, or :delete) on which the cache update should be triggered. Default is all actions.

  • :in_stage (Stage)

    the stage when the update is executed. Default is :integrate

Yields:

  • return an array of cards with solid cache that need to be updated



41
42
43
44
45
# File 'tmpsets/set/mod008-solid_cache/abstract/solid_cache.rb', line 41

def cache_update_trigger set_of_changed_card, args={}, &block
  define_event_to_update_expired_cached_cards(
    set_of_changed_card, args, :update_solid_cache, &block
  )
end

#define_event_to_update_expired_cached_cards(set_of_changed_card, args, method_name) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'tmpsets/set/mod008-solid_cache/abstract/solid_cache.rb', line 55

def define_event_to_update_expired_cached_cards set_of_changed_card, args,
                                                method_name
  args[:on] ||= [:create, :update, :delete]
  name = event_name set_of_changed_card, args
  stage = args[:in_stage] || :integrate
  Card::Set.register_set set_of_changed_card
  set_of_changed_card.event name, stage, args do
    Array(yield(self)).compact.each do |expired_cache_card|
      next unless expired_cache_card.solid_cache?
      expired_cache_card.send method_name
    end
  end
end

#event_name(set, args) ⇒ Object



69
70
71
72
73
74
75
# File 'tmpsets/set/mod008-solid_cache/abstract/solid_cache.rb', line 69

def event_name set, args
  changed_card_set = set.to_s.tr(":", "_").underscore
  solid_cache_set = to_s.tr(":", "_").underscore
  actions = Array.wrap(args[:on]).join("_")
  "update_#{solid_cache_set}_solid_cache_changed_by_" \
  "#{changed_card_set}_on_#{actions}".to_sym
end