Class: Chassis::MaglevRepo::MaglevMap

Inherits:
Object
  • Object
show all
Defined in:
lib/chassis/repo/maglev_repo.rb

Instance Method Summary collapse

Constructor Details

#initialize(store) ⇒ MaglevMap

Returns a new instance of MaglevMap.



4
5
6
# File 'lib/chassis/repo/maglev_repo.rb', line 4

def initialize store
  @store = store
end

Instance Method Details

#all(klass) ⇒ Object



24
25
26
# File 'lib/chassis/repo/maglev_repo.rb', line 24

def all(klass)
  class_map(klass).values
end

#clearObject



28
29
30
31
# File 'lib/chassis/repo/maglev_repo.rb', line 28

def clear
  store.clear
  Maglev.commit
end

#delete(record) ⇒ Object



19
20
21
22
# File 'lib/chassis/repo/maglev_repo.rb', line 19

def delete(record)
  record_map(record).delete record.id
  Maglev.commit
end

#get(klass, id) ⇒ Object



13
14
15
16
17
# File 'lib/chassis/repo/maglev_repo.rb', line 13

def get(klass, id)
  class_map(klass).fetch id do
    fail RecordNotFoundError.new(klass, id)
  end
end

#set(record) ⇒ Object



8
9
10
11
# File 'lib/chassis/repo/maglev_repo.rb', line 8

def set(record)
  record_map(record)[record.id] = record
  Maglev.commit
end