Class: Squealer::Database::Source
Overview
Connection
Instance Attribute Summary collapse
-
#counts ⇒ Object
readonly
Returns the value of attribute counts.
-
#cursor ⇒ Object
readonly
Returns the value of attribute cursor.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(dbc, collection) ⇒ Source
constructor
A new instance of Source.
- #source(conditions) ⇒ Object
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
#counts ⇒ Object (readonly)
Returns the value of attribute counts.
60 61 62 |
# File 'lib/squealer/database.rb', line 60 def counts @counts end |
#cursor ⇒ Object (readonly)
Returns the value of attribute cursor.
60 61 62 |
# File 'lib/squealer/database.rb', line 60 def cursor @cursor end |
Instance Method Details
#each ⇒ Object
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 |