Class: CanTango::Ability::Cache::Writer

Inherits:
Object
  • Object
show all
Includes:
Helpers::Debug
Defined in:
lib/cantango/ability/cache/writer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::Debug

#debug

Constructor Details

#initialize(cache) ⇒ Writer

Returns a new instance of Writer.



11
12
13
# File 'lib/cantango/ability/cache/writer.rb', line 11

def initialize cache
  @cache = cache
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



7
8
9
# File 'lib/cantango/ability/cache/writer.rb', line 7

def cache
  @cache
end

#cache_keyObject (readonly)

Returns the value of attribute cache_key.



7
8
9
# File 'lib/cantango/ability/cache/writer.rb', line 7

def cache_key
  @cache_key
end

Instance Method Details

#save(key, rules) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/cantango/ability/cache/writer.rb', line 15

def save key, rules
  cache.invalidate!
  return if prepared_rules.blank?
  debug "writing #{prepared_rules.size} rules to cache: #{key}"
  cache.rules_cache.save cache.key, prepared_rules
  session[cache_key] = cache.key if session
end