Class: DirSync::Traverser
- Inherits:
-
Object
- Object
- DirSync::Traverser
- Defined in:
- lib/dir_sync/traverser.rb
Constant Summary collapse
- TOLERANCE =
5
- IGNORE_PATTERNS =
[ /\.DS_Store$/, /\/\._/ ]
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
Instance Method Summary collapse
- #advance ⇒ Object
- #cp(*traversers) ⇒ Object
- #description ⇒ Object
- #empty? ⇒ Boolean
- #equivalent?(traverser) ⇒ Boolean
- #ignored? ⇒ Boolean
-
#initialize(path, file_system) ⇒ Traverser
constructor
A new instance of Traverser.
- #name ⇒ Object
- #rm ⇒ Object
- #ts ⇒ Object
Constructor Details
#initialize(path, file_system) ⇒ Traverser
Returns a new instance of Traverser.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/dir_sync/traverser.rb', line 15 def initialize path, file_system @file_system = file_system @base = Pathname.new path @base.mkpath @fiber = Fiber.new do @base.find { |child| Fiber.yield child if child.file? } Fiber.yield nil end @current = @fiber.resume end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
7 8 9 |
# File 'lib/dir_sync/traverser.rb', line 7 def base @base end |
Instance Method Details
#advance ⇒ Object
30 31 32 |
# File 'lib/dir_sync/traverser.rb', line 30 def advance @current = @fiber.resume if @current end |
#cp(*traversers) ⇒ Object
50 51 52 53 54 |
# File 'lib/dir_sync/traverser.rb', line 50 def cp *traversers traversers.each do |t| @file_system.cp @current.to_s, "#{t.base}/#{name}" unless equivalent? t end end |
#description ⇒ Object
26 27 28 |
# File 'lib/dir_sync/traverser.rb', line 26 def description empty? ? 'empty' : "#{name}:#{ts}" end |
#empty? ⇒ Boolean
42 43 44 |
# File 'lib/dir_sync/traverser.rb', line 42 def empty? @current.nil? end |
#equivalent?(traverser) ⇒ Boolean
60 61 62 |
# File 'lib/dir_sync/traverser.rb', line 60 def equivalent? traverser name == traverser.name and (ts - traverser.ts).abs <= TOLERANCE end |
#ignored? ⇒ Boolean
46 47 48 |
# File 'lib/dir_sync/traverser.rb', line 46 def ignored? IGNORE_PATTERNS.any? {|pattern| pattern.match name } end |
#name ⇒ Object
34 35 36 |
# File 'lib/dir_sync/traverser.rb', line 34 def name @current.relative_path_from(@base).to_s if @current end |
#rm ⇒ Object
56 57 58 |
# File 'lib/dir_sync/traverser.rb', line 56 def rm @file_system.rm @current.to_s end |
#ts ⇒ Object
38 39 40 |
# File 'lib/dir_sync/traverser.rb', line 38 def ts @current.mtime.to_i if @current end |