Class: Mongoose::Collection

Inherits:
Object show all
Includes:
Enumerable
Defined in:
lib/mongoose/table.rb

Instance Method Summary collapse

Constructor Details

#initialize(owner = nil, records = []) ⇒ Collection

Returns a new instance of Collection.



554
555
556
557
# File 'lib/mongoose/table.rb', line 554

def initialize(owner=nil, records=[])
  @owner = owner
  @records = records
end

Instance Method Details

#<<(rec) ⇒ Object



563
564
565
566
567
# File 'lib/mongoose/table.rb', line 563

def <<(rec)
  col_name = (@owner.class.table_name.to_s + "_id").to_sym
  rec.send("#{col_name}=".to_sym, @owner.instance_eval { @id })
  rec.save
end

#append(rec) ⇒ Object



569
570
571
# File 'lib/mongoose/table.rb', line 569

def append(rec)
  self << rec
end

#eachObject



559
560
561
# File 'lib/mongoose/table.rb', line 559

def each
  @records.each { |rec| yield rec }
end

#sizeObject



573
574
575
# File 'lib/mongoose/table.rb', line 573

def size
  @records.size
end