Class: Increment::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/increment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(given_number = nil, name = nil) ⇒ Runner

Returns a new instance of Runner.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/increment.rb', line 7

def initialize given_number=nil, name=nil
  @name = name || "undefined"

  @filename = File.join(ENV["HOME"], ".increment")
  @store = YAML::Store.new @filename
  create_new unless File.exists? @filename

  if given_number.nil?
    @number = number_in_file || 0
  else
    @number = given_number
    write given_number
  end
end

Instance Attribute Details

#readonlyObject

Returns the value of attribute readonly.



5
6
7
# File 'lib/increment.rb', line 5

def readonly
  @readonly
end

Instance Method Details

#incrementObject



22
23
24
25
26
27
28
# File 'lib/increment.rb', line 22

def increment
  unless @readonly
    @number += 1
    write @number
  end
  self
end

#listObject



34
35
36
37
38
39
40
41
42
# File 'lib/increment.rb', line 34

def list
  list = []
  @store.transaction(false) do
    @store.roots.each do |root|
      list << "#{root}:#{@store[root]}"
    end
  end
  list
end

#numberObject



30
31
32
# File 'lib/increment.rb', line 30

def number
  @number
end