Class: Mongoose::Collection
- Includes:
- Enumerable
- Defined in:
- lib/mongoose/table.rb
Instance Method Summary collapse
- #<<(rec) ⇒ Object
- #append(rec) ⇒ Object
- #each ⇒ Object
-
#initialize(owner = nil, records = []) ⇒ Collection
constructor
A new instance of Collection.
- #size ⇒ Object
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 |
#each ⇒ Object
792 793 794 |
# File 'lib/mongoose/table.rb', line 792 def each @records.each { |rec| yield rec } end |
#size ⇒ Object
806 807 808 |
# File 'lib/mongoose/table.rb', line 806 def size @records.size end |