Class: NcsNavigator::Warehouse::Contents
- Inherits:
-
Object
- Object
- NcsNavigator::Warehouse::Contents
- Includes:
- Enumerable
- Defined in:
- lib/ncs_navigator/warehouse/contents.rb
Overview
Provides an Enumerable over all of the content for some or all of the tables in a warehouse instance. Provides streaming results over batches for large content sets.
Instance Attribute Summary collapse
-
#block_size ⇒ Numeric
readonly
The maximum number of records to load into memory before yielding them to the consumer.
-
#filters ⇒ CompositeFilter
readonly
The filters in use on this transformer.
-
#models ⇒ Array<Class>
readonly
The warehouse models whose records will be enumerated by this instance.
Instance Method Summary collapse
-
#each ⇒ Object
Yields each instance of every configured #models in turn.
-
#initialize(config, options = {}) ⇒ Contents
constructor
Create a new Contents.
Constructor Details
#initialize(config, options = {}) ⇒ Contents
Create a new NcsNavigator::Warehouse::Contents.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ncs_navigator/warehouse/contents.rb', line 40 def initialize(config, ={}) @configuration = config @record_count = 0 @block_size = [:'block-size'] || 5000 @models = if [:tables] [:tables].collect { |t| t.to_s }.collect { |t| config.models_module.mdes_order.find { |model| model.mdes_table_name == t } } else config.models_module.mdes_order end filter_list = [:filters] @filters = NcsNavigator::Warehouse::Filters::CompositeFilter.new( filter_list ? [*filter_list].compact : []) end |
Instance Attribute Details
#block_size ⇒ Numeric (readonly)
Returns the maximum number of records to load into memory before yielding them to the consumer.
23 24 25 |
# File 'lib/ncs_navigator/warehouse/contents.rb', line 23 def block_size @block_size end |
#filters ⇒ CompositeFilter (readonly)
Returns the filters in use on this transformer.
18 19 20 |
# File 'lib/ncs_navigator/warehouse/contents.rb', line 18 def filters @filters end |
#models ⇒ Array<Class> (readonly)
Returns the warehouse models whose records will be enumerated by this instance.
14 15 16 |
# File 'lib/ncs_navigator/warehouse/contents.rb', line 14 def models @models end |
Instance Method Details
#each ⇒ Object
Yields each instance of every configured #models in turn.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ncs_navigator/warehouse/contents.rb', line 61 def each models.each do |model| key = model.key.first.name.to_sym count = model.count offset = 0 while offset < count model.all(:limit => block_size, :offset => offset, :order => key.asc).each do |instance| filters.call([instance]).each do |filtered_record| yield filtered_record end end offset += block_size end end end |