Sha256: c01c7d58301424cac5f586ab04631d47db915c831dcb6d05cc5c1111d9ed1619

Contents?: true

Size: 606 Bytes

Versions: 2

Compression:

Stored size: 606 Bytes

Contents

require 'active_record'
require 'active_support'
require 'digest/md5'

ActiveRecord::Base.class_eval {
  Array.class_eval {
    def cache_key
      if self.empty?
        'empty/' + self.object_id.to_s
      else
        ids_hash = Digest::MD5.hexdigest(self.collect{|item| item.id }.to_s)
        update_timestamp = max {|a,b| a.updated_at <=> b.updated_at }.updated_at.to_i.to_s
        create_timestamp = max {|a,b| a.created_at <=> b.created_at }.created_at.to_i.to_s
        self.first.class.to_s.tableize+'/'+length.to_s+'-'+ids_hash+'-'+create_timestamp+'-'+update_timestamp
      end
    end
  }
}

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
group_cache_key-0.4.1 ./lib/group_cache_key.rb
group_cache_key-0.4.0 lib/group_cache_key.rb