MemoryStorage
A very simple in memory storage utility class.
Installation
Add the gem to your Gemfile
gem 'memory_storage'
Usage
The only requirement to store objects with MemoryStorage is that persistent
objects must respond to #id
Examples:
class Item
attr_accessor :id, :name, :amount
def initialize(id, name, amount)
@id = id
@name = name
@amount = amount
end
end
item = Item.new(1, 'Item one', 10)
MemoryStorage.save(item)
MemoryStorage.find(1)
MemoryStorage.all
Enumerable
MemoryStorage includes Enumerable, so every method defined in Enumerable can be
used:
MemoryStorage.save(Item.new(1,'one', 1))
MemoryStorage.save(Item.new(2,'one', 2))
MemoryStorage.save(Item.new(3,'one', 3))
MemoryStorage.inject(0) {|sum, item| sum + item.amount }
Contributing
- Fork it
- 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 new Pull Request
License
See the LICENSE.