Sha256: 1db2a8432538211a0feb27665a5659b550ec612c3f577c7cc4c1753e17a8ef54

Contents?: true

Size: 1 KB

Versions: 7

Compression:

Stored size: 1 KB

Contents

module CanTango
  class Ability
    class Cache
      class Writer
        include CanTango::Helpers::Debug

        attr_reader :cache, :cache_key

        delegate :cache_key, :to => :cache

        def initialize cache
          @cache = cache
        end

        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

        protected

        def prepared_rules
          cache.compile_on? ? compiler.compile!(rules) : rules
        end

        def rules
          return cache.cached_rules if cache.cached_rules?
          cache.ability.send :rules # bad!? FIXME
        end

        def compiler
          cache.compiler
        end

        def session
          cache.session
        end

        def rules_cache
          cache.rules_cache
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
cantango-0.9.4.7 lib/cantango/ability/cache/writer.rb
cantango-0.9.4.6 lib/cantango/ability/cache/writer.rb
cantango-0.9.4.5 lib/cantango/ability/cache/writer.rb
cantango-0.9.4.3 lib/cantango/ability/cache/writer.rb
cantango-0.9.4.2 lib/cantango/ability/cache/writer.rb
cantango-0.9.4.1 lib/cantango/ability/cache/writer.rb
cantango-0.9.4 lib/cantango/ability/cache/writer.rb