Module: Bandicoot

Defined in:
lib/bandicoot.rb,
lib/bandicoot/context.rb,
lib/bandicoot/version.rb,
lib/bandicoot/save_file.rb,
lib/bandicoot/save_point_hash.rb

Defined Under Namespace

Classes: AlreadyStartedError, Context, NotStartedError, SaveFile, SavePointHash

Constant Summary collapse

VERSION =
"0.1.0"
@@current =
nil

Class Method Summary collapse

Class Method Details

.currentObject



19
20
21
# File 'lib/bandicoot.rb', line 19

def self.current
  @@current
end

.pop_contextObject



37
38
39
# File 'lib/bandicoot.rb', line 37

def self.pop_context
  @@current = Bandicoot.current.parent
end

.push_context(opts = {}) ⇒ Object



33
34
35
# File 'lib/bandicoot.rb', line 33

def self.push_context(opts={})
  @@current = Bandicoot::Context.new(opts.merge(:parent => Bandicoot.current))
end

.save_point(key, &blk) ⇒ Object

Raises:



23
24
25
26
27
28
29
30
31
# File 'lib/bandicoot.rb', line 23

def self.save_point(key, &blk)
  raise NotStartedError unless Bandicoot.current
  Bandicoot.push_context(:key => key)
  begin
    Bandicoot.current.run(blk)
  ensure
    Bandicoot.pop_context
  end
end

.start(opts = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/bandicoot.rb', line 8

def self.start(opts={})
  raise AlreadyStartedError if Bandicoot.current
  Bandicoot.push_context(opts)
  begin
    yield
  ensure
    Bandicoot.current.save_file.close
    Bandicoot.pop_context
  end
end