class EacRubyUtils::Fs::Traverser
Attributes
check_directory[RW]
check_file[RW]
recursive[RW]
sort[RW]
Public Instance Methods
check_path(path)
click to toggle source
# File lib/eac_ruby_utils/fs/traverser.rb, line 8 def check_path(path) path = ::Pathname.new(path.to_s) unless path.is_a?(::Pathname) internal_check_path(path, 0) end
recursive?()
click to toggle source
# File lib/eac_ruby_utils/fs/traverser.rb, line 17 def recursive? boolean_value(recursive) end
sort?()
click to toggle source
# File lib/eac_ruby_utils/fs/traverser.rb, line 21 def sort? boolean_value(sort) end
Private Instance Methods
boolean_value(source_value)
click to toggle source
# File lib/eac_ruby_utils/fs/traverser.rb, line 27 def boolean_value(source_value) source_value = source_value.call if source_value.respond_to?(:call) source_value ? true : false end
each_child(dir, &block)
click to toggle source
# File lib/eac_ruby_utils/fs/traverser.rb, line 32 def each_child(dir, &block) if sort? dir.each_child.sort_by { |p| [p.to_s] }.each(&block) else dir.each_child(&block) end end
inner_check_directory(dir, level)
click to toggle source
# File lib/eac_ruby_utils/fs/traverser.rb, line 44 def inner_check_directory(dir, level) return unless process_directory?(level) user_check_directory(dir) each_child(dir) do |e| next unless !e.basename.to_s.start_with?('.') || hidden_directories? internal_check_path(e, level + 1) end end
internal_check_path(path, level)
click to toggle source
# File lib/eac_ruby_utils/fs/traverser.rb, line 55 def internal_check_path(path, level) if path.file? user_check_file(path) elsif path.directory? inner_check_directory(path, level) end end
process_directory?(level)
click to toggle source
# File lib/eac_ruby_utils/fs/traverser.rb, line 40 def process_directory?(level) level.zero? || recursive? end
user_check_directory(path)
click to toggle source
# File lib/eac_ruby_utils/fs/traverser.rb, line 67 def user_check_directory(path) check_directory&.call(path) end
user_check_file(path)
click to toggle source
# File lib/eac_ruby_utils/fs/traverser.rb, line 63 def user_check_file(path) check_file&.call(path) end