Sha256: 971cb96fd422b852768a2327f55c7371bb620fe282f788fe74293da3664bf212

Contents?: true

Size: 622 Bytes

Versions: 6

Compression:

Stored size: 622 Bytes

Contents

module Cache
  module Object
    class InstanceDecorator < Struct.new(:instance, :mappings)
      def keys
        [canonical_cache_key] + mapping_cache_keys
      end

      private

      def mapping_cache_keys
        mappings.map do |mapping|
          attributes = {}.tap do |obj|
            mapping.each { |attr| obj[attr] = instance.send(attr) }
          end
          KeyGenerator.key_for_mapping(instance.class.name, attributes)
        end
      end

      def canonical_cache_key
        KeyGenerator.key_for_object(instance.class.name, instance.send(instance.class.primary_key))
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
cache-object-0.2.0 lib/cache/object/instance_decorator.rb
cache-object-0.1.0 lib/cache/object/instance_decorator.rb
cache-object-0.0.7 lib/cache/object/instance_decorator.rb
cache-object-0.0.6 lib/cache/object/instance_decorator.rb
cache-object-0.0.5 lib/cache/object/instance_decorator.rb
cache-object-0.0.4 lib/cache/object/instance_decorator.rb