Class: Squealer::Database::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/squealer/database.rb

Overview

Connection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dbc, collection) ⇒ Source

Returns a new instance of Source.



62
63
64
65
# File 'lib/squealer/database.rb', line 62

def initialize(dbc, collection)
  @counts = {:exported => 0, :imported => 0}
  @collection = dbc.collection(collection)
end

Instance Attribute Details

#countsObject (readonly)

Returns the value of attribute counts.



60
61
62
# File 'lib/squealer/database.rb', line 60

def counts
  @counts
end

#cursorObject (readonly)

Returns the value of attribute cursor.



60
61
62
# File 'lib/squealer/database.rb', line 60

def cursor
  @cursor
end

Instance Method Details

#eachObject



74
75
76
77
78
79
80
81
82
83
# File 'lib/squealer/database.rb', line 74

def each
  @progress_bar.start if @progress_bar
  @cursor.each do |row|
    @counts[:imported] += 1
    yield row
    @progress_bar.tick if @progress_bar
    @counts[:exported] += 1
  end
  @progress_bar.finish if @progress_bar
end

#source(conditions) ⇒ Object



67
68
69
70
71
72
# File 'lib/squealer/database.rb', line 67

def source(conditions)
  @cursor = block_given? ? yield(@collection) : @collection.find(conditions)
  @counts[:total] = cursor.count
  @progress_bar = Squealer::ProgressBar.new(cursor.count)
  self
end