Class: Click::Database::Writer

Inherits:
Object
  • Object
show all
Includes:
Observer
Defined in:
lib/click/database/writer.rb

Instance Method Summary collapse

Methods included from Observer

#before_click

Constructor Details

#initialize(db) ⇒ Writer

Returns a new instance of Writer.



8
9
10
# File 'lib/click/database/writer.rb', line 8

def initialize(db)
  @db = db
end

Instance Method Details

#after_click(clicker) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/click/database/writer.rb', line 12

def after_click(clicker)
  snapshot = Models::Snapshot.create(timestamp: Time.now)
  object_count_hashes = clicker.object_counts.map do |klass, count|
    {snapshot_id: snapshot.id, class_name: klass.to_s, count: count}
  end

  Models::ObjectCount.dataset.multi_insert(object_count_hashes)
end