Class: Flatito::TreeIterator
- Inherits:
-
Object
- Object
- Flatito::TreeIterator
- Includes:
- Enumerable
- Defined in:
- lib/flatito/tree_iterator.rb
Instance Attribute Summary collapse
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
-
#gitignore ⇒ Object
readonly
Returns the value of attribute gitignore.
-
#skip_hidden ⇒ Object
readonly
Returns the value of attribute skip_hidden.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(base_path, options = {}) ⇒ TreeIterator
constructor
A new instance of TreeIterator.
- #tree(parent, &block) ⇒ Object
Constructor Details
#initialize(base_path, options = {}) ⇒ TreeIterator
Returns a new instance of TreeIterator.
12 13 14 15 16 |
# File 'lib/flatito/tree_iterator.rb', line 12 def initialize(base_path, = {}) @base_path = base_path @skip_hidden = .fetch(:skip_hidden, true) @gitignore = .fetch(:gitignore, true) end |
Instance Attribute Details
#base_path ⇒ Object (readonly)
Returns the value of attribute base_path.
10 11 12 |
# File 'lib/flatito/tree_iterator.rb', line 10 def base_path @base_path end |
#gitignore ⇒ Object (readonly)
Returns the value of attribute gitignore.
10 11 12 |
# File 'lib/flatito/tree_iterator.rb', line 10 def gitignore @gitignore end |
#skip_hidden ⇒ Object (readonly)
Returns the value of attribute skip_hidden.
10 11 12 |
# File 'lib/flatito/tree_iterator.rb', line 10 def skip_hidden @skip_hidden end |
Instance Method Details
#each(&block) ⇒ Object
18 19 20 |
# File 'lib/flatito/tree_iterator.rb', line 18 def each(&block) tree(Pathname.new(base_path), &block) end |
#tree(parent, &block) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/flatito/tree_iterator.rb', line 22 def tree(parent, &block) if parent.directory? return if parent.symlink? return if gitignore && ignored_dir?(parent) parent.each_child.each do |pathname| next if skip_hidden && pathname.basename.to_s[0] == "." tree(pathname, &block) end else yield(parent) end rescue Errno::ELOOP => e warn "Error reading #{parent}, #{e.}" [] end |