Class: Findler::Iterator

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/findler/iterator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(findler, path, parent_iterator = nil) ⇒ Iterator

Returns a new instance of Iterator.



10
11
12
13
14
15
# File 'lib/findler/iterator.rb', line 10

def initialize(findler, path, parent_iterator = nil)
  @configuration = findler
  @path = Path.clean(path).freeze
  @parent = parent_iterator
  @visited = []
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/findler/iterator.rb', line 8

def path
  @path
end

Instance Method Details

#next_fileObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/findler/iterator.rb', line 17

def next_file
  return nil unless @path.exist?

  if @sub_iter
    nxt = @sub_iter.next_file
    return nxt unless nxt.nil?
    mark_visited(@sub_iter.path)
    @sub_iter = nil
  end

  nxt = next_visitable_child
  return nil if nxt.nil?

  if nxt.directory?
    @sub_iter = Iterator.new(@configuration, nxt, self)
    self.next_file
  else
    mark_visited(nxt)
    nxt
  end
end