Class: RIQ::BatchManager
- Inherits:
-
Object
- Object
- RIQ::BatchManager
- Defined in:
- lib/riq/batch_manager.rb
Overview
Manages caching and fetching for a certain type of child object.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#fetch_options ⇒ Hash
Current fetch options.
Instance Method Summary collapse
-
#each(&blok) ⇒ Object
Iterator for each item in the manager.
-
#first ⇒ RIQObject
Returns the first child object, mainly used for testing.
-
#initialize(klass, opts = {}) ⇒ BatchManager
constructor
A new instance of BatchManager.
Constructor Details
#initialize(klass, opts = {}) ⇒ BatchManager
Returns a new instance of BatchManager.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/riq/batch_manager.rb', line 11 def initialize(klass, opts = {}) @klass = klass raise(RIQError, 'Must pass a RIQ Class') unless @klass.ancestors.include?(RIQ::RIQObject) @fetch_options = {} reset_cache # cause otherwise it's a variable self.send(:fetch_options=, opts) @client = RIQ.client end |
Instance Attribute Details
#fetch_options ⇒ Hash
Returns current fetch options.
7 8 9 |
# File 'lib/riq/batch_manager.rb', line 7 def @fetch_options end |
Instance Method Details
#each(&blok) ⇒ Object
Iterator for each item in the manager. Pass a block to it!
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/riq/batch_manager.rb', line 27 def each(&blok) reset_cache loop do x = next_item if x blok.call(x) else return end end end |
#first ⇒ RIQObject
Returns the first child object, mainly used for testing
41 42 43 44 45 46 47 48 |
# File 'lib/riq/batch_manager.rb', line 41 def first reset_cache o = .dup self.send(:fetch_options=, {_limit: 1}) r = fetch_page.first self.send(:fetch_options=, o) r end |