Module: MemModel::RootedBase::ClassMethods

Defined in:
lib/mem_model/rooted_base.rb

Instance Method Summary collapse

Instance Method Details

#abortObject



26
27
28
29
# File 'lib/mem_model/rooted_base.rb', line 26

def abort
  Maglev.abort_transaction if maglev?
  true
end

#commitObject



31
32
33
34
# File 'lib/mem_model/rooted_base.rb', line 31

def commit
  Maglev.commit_transaction if maglev?
  true
end

#container_keyObject



13
14
15
# File 'lib/mem_model/rooted_base.rb', line 13

def container_key
  name.to_sym
end

#persistent(&block) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/mem_model/rooted_base.rb', line 36

def persistent(&block)
  abort
  maglev? ?
    Maglev.persistent { block.call } :
    block.call
  commit
end

#rootObject



22
23
24
# File 'lib/mem_model/rooted_base.rb', line 22

def root
  @root ||= root_container::PERSISTENT_ROOT
end

#root_containerObject



9
10
11
# File 'lib/mem_model/rooted_base.rb', line 9

def root_container
  MemModel.maglev? ? Maglev : MemModel
end

#storeObject



17
18
19
20
# File 'lib/mem_model/rooted_base.rb', line 17

def store
  root[:MemModel] ||= {}
  root[:MemModel][container_key] ||= store_class.new
end