Repositories

I’ve got a bunch of repositories hanging out on my hard drive. (Right now, I have about 40 local gems, only a few of those are published). I keep re-inventing the wheel, so I’m putting them here. The power of a repository is that is is self-cleaning, works like a cache with an eviction policy. I’ve pulled in some easy ones for now (array_cache and hash_cache), and I’ll bring in some graph and redis repositories when I can extract them out cleanly. I should also move TenaciousG and FarGratr into this project and give them some caching functions.

Usage

require 'repositories/array_cache'
@a = (1..15).inject(ArrayCache.new) {|a, e| a << e }
# [6,7,8,9,10,11,12,13,14,15]
@a = (1..15).inject(ArrayCache.new(:n => 2)) {|a, e| a << e }
# [14,15]

require 'repositories/hash_cache'
@h = HashCache.new
(1..15).each { |i| @h[i] = i }
@h.hash #=> {11=>11, 6=>6, 12=>12, 7=>7, 13=>13, 8=>8, 14=>14, 9=>9, 15=>15, 10=>10}

@h = HashCache.new(:n => 2)
(1..15).each { |i| @h[i] = i }
@h.hash #=> {14=>14, 15=>15}

Installation

sudo gem install davidrichards-repositories

Dependencies

None at this point, but will have some optional dependencies for the other repositories.

Copyright © 2009 David Richards. See LICENSE for details.