MongoMethodStorable
MongoMethodStorage allows you to store the output of methods in a Mongoid::Document class into MongoDB dynamic fields. It also lazily stores the output, in that the value is only stored the first time the method is called on a given object. Subsequent calls to the method will just read the attribute value from the document, eliminating the "cost" of executing the method.
Installation
Add this line to your application's Gemfile:
gem 'mongo_method_storable'
And then execute:
$ bundle
Or install it yourself as:
$ gem install mongo_method_storable
Usage
include MongoMethodStorable
def some_method
# complex/expensive algorithm
end
mongo_store :some_method
Limitations
- Methods can take no arguments (currently)
- There is no option (currently) to force the method to be evaluated after the first time.
- No tests have been written on this code (caveat: it is being used in at least one production application)
- This is my first "real" published Ruby gem
- A bunch of other limitations I'm sure I'll think of over time
Contributing
- Fork it ( https://github.com/BigGillyStyle/mongo_method_storable/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request