Sha256: 72d949373e353043edbc107d52e70f14e0ba96a621ada49006f089ff5f0baa5b

Contents?: true

Size: 635 Bytes

Versions: 1

Compression:

Stored size: 635 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 = mapping.inject({}) do |memo, attr|
            memo[attr] = instance.send(attr)
            memo
          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

1 entries across 1 versions & 1 rubygems

Version Path
cache-object-0.0.3 lib/cache/object/instance_decorator.rb