Class: Increment::Runner
- Inherits:
-
Object
- Object
- Increment::Runner
- Defined in:
- lib/increment.rb
Instance Attribute Summary collapse
-
#readonly ⇒ Object
Returns the value of attribute readonly.
Instance Method Summary collapse
- #increment ⇒ Object
-
#initialize(given_number = nil, name = nil) ⇒ Runner
constructor
A new instance of Runner.
- #list ⇒ Object
- #number ⇒ Object
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
#readonly ⇒ Object
Returns the value of attribute readonly.
5 6 7 |
# File 'lib/increment.rb', line 5 def readonly @readonly end |
Instance Method Details
#increment ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/increment.rb', line 22 def increment unless @readonly @number += 1 write @number end self end |
#list ⇒ Object
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 |
#number ⇒ Object
30 31 32 |
# File 'lib/increment.rb', line 30 def number @number end |