Class: Metacrunch::DB::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/metacrunch/db/source.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  rows_per_fetch: 1000,
  strategy: :filter,
  filter_values: nil
}

Instance Method Summary collapse

Constructor Details

#initialize(sequel_dataset, options = {}) ⇒ Source

Returns a new instance of Source.



12
13
14
15
16
17
18
19
# File 'lib/metacrunch/db/source.rb', line 12

def initialize(sequel_dataset, options = {})
  @dataset = sequel_dataset
  @options = DEFAULT_OPTIONS.merge(options)

  unless @dataset.opts[:order]
    raise ArgumentError, "The dataset must be ordered."
  end
end

Instance Method Details

#each(&block) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/metacrunch/db/source.rb', line 21

def each(&block)
  return enum_for(__method__) unless block_given?

  @dataset.paged_each(
    rows_per_fetch: @options[:rows_per_fetch],
    strategy: @options[:strategy],
    filter_values: @options[:filter_values]
  ) do |row|
    yield(row)
  end

  self
end