Class: Gisele::VM::ProgList::Memory

Inherits:
Storage show all
Defined in:
lib/gisele/vm/prog_list/memory.rb

Instance Attribute Summary

Attributes inherited from Storage

#options

Instance Method Summary collapse

Methods inherited from Storage

#save

Methods inherited from Component

#connect, #connected!, #connected?, #disconnect, #registered, #registered!, #registered?, #unregistered, #vm

Constructor Details

#initialize(options = {}) ⇒ Memory



6
7
8
9
# File 'lib/gisele/vm/prog_list/memory.rb', line 6

def initialize(options = {})
  super
  @progs = []
end

Instance Method Details

#clearObject



24
25
26
# File 'lib/gisele/vm/prog_list/memory.rb', line 24

def clear
  @progs = []
end

#fetch(puid) ⇒ Object



11
12
13
# File 'lib/gisele/vm/prog_list/memory.rb', line 11

def fetch(puid)
  @progs[is_a_valid_puid!(puid)].dup
end

#pick(restriction, &bl) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/gisele/vm/prog_list/memory.rb', line 15

def pick(restriction, &bl)
  keys = restriction.keys
  candidate = @progs.select{|p|
    p.to_hash(keys) == restriction
  }.sample
  bl.call if bl and candidate.nil?
  candidate
end

#to_relation(restriction = nil) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/gisele/vm/prog_list/memory.rb', line 28

def to_relation(restriction = nil)
  progs = @progs
  if restriction
    keys  = restriction.keys
    progs = progs.select{|p| p.to_hash(keys) == restriction}
  end
  progs = progs.map{|p| p.to_hash}
  Alf::Relation(progs)
end