Class: Seedy::AbstractBuffer

Inherits:
Object
  • Object
show all
Defined in:
lib/seedy/buffer/abstract_buffer.rb

Direct Known Subclasses

DatabaseBuffer

Constant Summary collapse

@@buffer =
[]
@@limit =
5

Class Method Summary collapse

Class Method Details

.<<(record) ⇒ Object

Raises:



8
9
10
11
12
# File 'lib/seedy/buffer/abstract_buffer.rb', line 8

def <<(record)
  raise InvalidRecord, record.table_name + ": " + record.errors.to_a.join(", ") unless record.valid?
  @@buffer << record
  flush if @@buffer.length >= @@limit
end

.flushObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/seedy/buffer/abstract_buffer.rb', line 13

def flush
  puts "Flushing!"
  @@buffer.length.times {
    record = @@buffer.shift
    if record.valid?
      puts record.to_sql
    else
      puts record.errors
    end
  }
end