PersistentBlocks
Persist the output of ruby blocks
Installation
Add this line to your application's Gemfile:
gem 'persistent_blocks'
And then execute:
$ bundle
Or install it yourself as:
$ gem install persistent_blocks
Usage
put the following in a rakefile.rb
require 'persistent_blocks'
extend PersistentBlocks
persist :some_persistent_data do
# Do a long running process to generate some data called :some_persistent_data
# You don't want to repeat the calculation unecessarily, so persist will
# automatically persist it to disk for you.
sleep(1)
puts "I will return an array that will be automatically persisted to disk"
puts "Next time you run the rakefile I won't be run."
["First persisted element", "Second persisted element"]
end
persist do |some_persistent_data|
puts "Now I will print out the persistent data"
p some_persistent_data # => ["First persisted element", "Second persisted element"]
end