Created
January 14, 2011 10:07
-
-
Save jhchabran/779437 to your computer and use it in GitHub Desktop.
Little experiment with cache keys
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Cachable | |
def self.included(receiver) | |
receiver.class_attribute :cachable | |
receiver.cachable = Keystore.new | |
receiver.send(:helper_method, :cachable) | |
end | |
class Keystore | |
def define name, &block | |
(class << self; self; end).send :define_method, name, &block | |
end | |
end | |
end | |
# Spec | |
class Dummy < ApplicationController | |
include Cachable | |
end | |
describe Cachable do | |
before(:each) do | |
Dummy.cachable.define :spotlight do |a,b| | |
"spotlight_#{a}_#{b}" | |
end | |
end | |
it "should generate a key for spotlight" do | |
Dummy.cachable.spotlight(1,2).should == "spotlight_1_2" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment