Class: Graml::TreeIterator
- Inherits:
-
Object
- Object
- Graml::TreeIterator
- Defined in:
- lib/graml/tree_iterator.rb
Instance Attribute Summary collapse
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
-
#skip_hidden ⇒ Object
readonly
Returns the value of attribute skip_hidden.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(base_path, skip_hidden: true) ⇒ TreeIterator
constructor
A new instance of TreeIterator.
- #tree(parent, &block) ⇒ Object
Constructor Details
#initialize(base_path, skip_hidden: true) ⇒ TreeIterator
Returns a new instance of TreeIterator.
7 8 9 10 |
# File 'lib/graml/tree_iterator.rb', line 7 def initialize(base_path, skip_hidden: true) @base_path = base_path @skip_hidden = skip_hidden end |
Instance Attribute Details
#base_path ⇒ Object (readonly)
Returns the value of attribute base_path.
5 6 7 |
# File 'lib/graml/tree_iterator.rb', line 5 def base_path @base_path end |
#skip_hidden ⇒ Object (readonly)
Returns the value of attribute skip_hidden.
5 6 7 |
# File 'lib/graml/tree_iterator.rb', line 5 def skip_hidden @skip_hidden end |
Instance Method Details
#each(&block) ⇒ Object
12 13 14 |
# File 'lib/graml/tree_iterator.rb', line 12 def each(&block) tree(Pathname.new(base_path), &block) end |
#tree(parent, &block) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/graml/tree_iterator.rb', line 16 def tree(parent, &block) if parent.directory? return if parent.symlink? parent.children.each do |pathname| next if skip_hidden && pathname.basename.to_s.start_with?(".") tree(pathname, &block) end else yield(parent) end rescue Errno::ELOOP => e warn "Error reading #{parent}, #{e.}" [] end |