Sha256: d44ad2b38444967168ec740115dbf9af73ec0ad20cd2dbbc54e20ac7f796212b
Contents?: true
Size: 640 Bytes
Versions: 13
Compression:
Stored size: 640 Bytes
Contents
module Bait module SimpleQuery def self.extended(base) base.after_create do id_list = self.class.ids id_list << self.id self.class.ids = id_list end base.after_destroy do self.class.ids = self.class.ids.reject{|id| id == self.id} end end def id_list_key "#{self.name.split('::').last.downcase}_ids" end def ids Bait.store.raw[id_list_key] ||= [] end def ids=(new_ids) Bait.store.raw[id_list_key] = new_ids end def all ids.map{|id| self.read(id)} end def last self.read(self.ids.last) end end end
Version data entries
13 entries across 13 versions & 1 rubygems