File: memory.rb

package info (click to toggle)
mikutter 3.8.6%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 10,544 kB
  • sloc: ruby: 20,548; sh: 99; makefile: 19
file content (18 lines) | stat: -rw-r--r-- 367 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# -*- coding: utf-8 -*-
class Diva::Model::Memory
  include Diva::DataSource

  def initialize(klass=Diva::Model)
    @storage = WeakStorage.new(Integer, klass) end

  def findbyid(id, policy)
    if id.is_a? Enumerable
      id.map{ |i| @storage[i.to_i] }
    else
      @storage[id.to_i] end
  end

  def store_datum(datum)
    @storage[datum.id] = datum
  end
end