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.



787
788
789
790
# File 'lib/mongoose/table.rb', line 787

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

Instance Method Details

#<<(rec) ⇒ Object



796
797
798
799
800
# File 'lib/mongoose/table.rb', line 796

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



802
803
804
# File 'lib/mongoose/table.rb', line 802

def append(rec)
  self << rec
end

#eachObject



792
793
794
# File 'lib/mongoose/table.rb', line 792

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

#sizeObject



806
807
808
# File 'lib/mongoose/table.rb', line 806

def size
  @records.size
end