Class: DirSync::HistoryTraverser
- Inherits:
-
Object
- Object
- DirSync::HistoryTraverser
- Defined in:
- lib/dir_sync/history_traverser.rb
Constant Summary collapse
- REGEXP =
/:(\d+)$/
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#ts ⇒ Object
readonly
Returns the value of attribute ts.
Instance Method Summary collapse
- #advance ⇒ Object
- #close ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(name) ⇒ HistoryTraverser
constructor
A new instance of HistoryTraverser.
- #report(traverser) ⇒ Object
Constructor Details
#initialize(name) ⇒ HistoryTraverser
Returns a new instance of HistoryTraverser.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/dir_sync/history_traverser.rb', line 8 def initialize name home = File. '~' Pathname.new("#{home}/.dir_sync").mkpath @path_old = "#{home}/.dir_sync/#{name}" @path_new = "#{@path_old}.new" @new = File.open @path_new, 'w' @base = '<history>' if File.exist? @path_old @fiber = Fiber.new do File.open(@path_old) do |file| file.each {|line| Fiber.yield line.chomp} end Fiber.yield nil end @description = :nothing advance end end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
5 6 7 |
# File 'lib/dir_sync/history_traverser.rb', line 5 def base @base end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
5 6 7 |
# File 'lib/dir_sync/history_traverser.rb', line 5 def description @description end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/dir_sync/history_traverser.rb', line 5 def name @name end |
#ts ⇒ Object (readonly)
Returns the value of attribute ts.
5 6 7 |
# File 'lib/dir_sync/history_traverser.rb', line 5 def ts @ts end |
Instance Method Details
#advance ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/dir_sync/history_traverser.rb', line 27 def advance @description = @fiber.resume if @description if @description match = REGEXP.match @description raise "unable to parse line \"#{@description}\"" unless match @name = match.pre_match @ts = match[1].to_i end end |
#close ⇒ Object
37 38 39 40 |
# File 'lib/dir_sync/history_traverser.rb', line 37 def close @new.close `mv #{@path_new} #{@path_old}` end |
#empty? ⇒ Boolean
46 47 48 |
# File 'lib/dir_sync/history_traverser.rb', line 46 def empty? @description.nil? end |
#report(traverser) ⇒ Object
42 43 44 |
# File 'lib/dir_sync/history_traverser.rb', line 42 def report traverser @new.puts traverser.description end |