Module: Coffeeshop

Defined in:
lib/coffeeshop.rb,
lib/coffeeshop/version.rb

Constant Summary collapse

REDIS =
Redis.new
EXPIRE =
60 * 60
VERSION =
"1.0.2"

Class Method Summary collapse

Class Method Details

.digest(text) ⇒ Object



22
23
24
# File 'lib/coffeeshop.rb', line 22

def self.digest( text )
  Digest::MD5.hexdigest( text )
end

.key(digest) ⇒ Object



26
27
28
# File 'lib/coffeeshop.rb', line 26

def self.key( digest )
  "coffeeshop:#{digest}"
end

.to_js(path) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/coffeeshop.rb', line 11

def self.to_js( path )
  coffee = File.read( path )
  k = key( digest( coffee ) )
  unless js = REDIS.get( k )
    js = CoffeeScript.compile( coffee )
    REDIS.set( k, js )
  end
  REDIS.expire( k, EXPIRE )
  js
end