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

Version Path
bait-0.5.13 lib/bait/simple_query.rb
bait-0.5.12 lib/bait/simple_query.rb
bait-0.5.11 lib/bait/simple_query.rb
bait-0.5.10 lib/bait/simple_query.rb
bait-0.5.9 lib/bait/simple_query.rb
bait-0.5.6 lib/bait/simple_query.rb
bait-0.5.5 lib/bait/simple_query.rb
bait-0.5.4 lib/bait/simple_query.rb
bait-0.5.2 lib/bait/simple_query.rb
bait-0.5.1 lib/bait/simple_query.rb
bait-0.5.0 lib/bait/simple_query.rb
bait-0.4.1 lib/bait/simple_query.rb
bait-0.4.0 lib/bait/simple_query.rb