项目作者: cyclotron3k

项目描述 :
A caching wrapper for Enumerator
高级语言: Ruby
项目地址: git://github.com/cyclotron3k/caching_enumerator.git
创建时间: 2017-10-17T02:56:51Z
项目社区:https://github.com/cyclotron3k/caching_enumerator

开源协议:MIT License

下载


CachingEnumerator Build Status

A caching wrapper for Enumerator

Installation

Add this line to your application’s Gemfile:

  1. gem 'caching_enumerator'

And then execute:

  1. $ bundle

Or install it yourself as:

  1. $ gem install caching_enumerator

Usage

  1. require 'caching_enumerator'
  2. enum = CachingEnumerator.new do |yielder|
  3. 5.times do |i|
  4. puts "very expensive operation #{i}"
  5. yielder.yield i
  6. end
  7. end
  8. enum.take 2
  9. # very expensive operation 0
  10. # very expensive operation 1
  11. # => [0, 1]
  12. enum.take 3
  13. # very expensive operation 2
  14. # => [0, 1, 2]
  15. enum.next
  16. # => 0
  17. enum.next
  18. # => 1
  19. enum.next
  20. # => 2
  21. enum.next
  22. # very expensive operation 3
  23. # => 3
  24. enum.rewind.next
  25. # => 0
  26. # calling `reset` will clear the cache and rewind the internal pointers
  27. enum.reset.next
  28. # very expensive operation 0
  29. # => 0

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/cyclotron3k/caching_enumerator.

License

The gem is available as open source under the terms of the MIT License.