Skip to content

Instantly share code, notes, and snippets.

@guilhermechapiewski
Forked from sr/gist:91275
Created April 7, 2009 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guilhermechapiewski/91290 to your computer and use it in GitHub Desktop.
Save guilhermechapiewski/91290 to your computer and use it in GitHub Desktop.
Integrity auto-refresher
#!/usr/bin/env ruby
require "rubygems"
require "integrity"
class Refresher
JS = <<-EOS
<script type="text/javascript">
//<![CDATA[
setTimeout('location.reload()', %s * 1000)
//]]>
</script>
EOS
def initialize(app, interval)
@app = app
@interval = interval
end
def call(env)
response = @app.call(env)
return response unless env["PATH_INFO"] == "/"
body = ""; response.last.each { |s| body << s }
body.gsub!(/<\/head>/, (JS % @interval) + "\n</head>")
response[1]["Content-Length"] = body.size.to_s
[response.first, response[1], [body]]
end
end
Integrity.new
DataMapper.auto_migrate!
use Refresher, 5
run Integrity::App
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment