class RabbitHole::Base

Public Class Methods

new(yml_path = " click to toggle source
# File lib/rabbit_hole/base.rb, line 7
def initialize(yml_path = "#{Dir.home}/.rabbit_hole.yml")
  @yml_path = yml_path
end

Public Instance Methods

pop() click to toggle source
# File lib/rabbit_hole/base.rb, line 17
def pop
  with_stack do |stack|
    stack.pop
  end
end
push(task) click to toggle source
# File lib/rabbit_hole/base.rb, line 11
def push(task)
  with_stack do |stack|
    stack.push(task)
  end
end
size() click to toggle source
# File lib/rabbit_hole/base.rb, line 29
def size
  with_stack do |stack|
    stack.size
  end
end
tasks() click to toggle source
# File lib/rabbit_hole/base.rb, line 35
def tasks
  with_stack do |stack|
    stack
  end
end
top() click to toggle source
# File lib/rabbit_hole/base.rb, line 23
def top
  with_stack do |stack|
    stack.last
  end
end

Private Instance Methods

with_stack() { |stack| ... } click to toggle source
# File lib/rabbit_hole/base.rb, line 43
def with_stack

  if File.file?(@yml_path)
    stack = YAML.load_file(@yml_path)
  else
    stack ||= []
  end

  result = yield stack

  File.open(@yml_path, 'w') { |f| YAML.dump(stack, f) }

  result
end