Class: Trop::FileFinder
- Inherits:
-
Object
- Object
- Trop::FileFinder
- Defined in:
- lib/trop/file_finder.rb,
lib/trop/file_finder.rb
Class Method Summary collapse
- .collect_dir_tree(path) ⇒ Object
- .collect_md_tree(path) ⇒ Object
- .collect_sorted_readme(path) ⇒ Object
- .my_gemspec_fffind(*path) ⇒ Object
Instance Method Summary collapse
- #collect_dir_tree(spath) ⇒ Object
- #collect_gem_tree(path) ⇒ Object
- #collect_md_tree(spath) ⇒ Object
- #collect_readme_md_tree(spath) ⇒ Object
- #collect_sorted_readme(spath) ⇒ Object
- #dffind(_path) ⇒ Object
- #fffind(_path) ⇒ Object
- #filter_pages(pages) ⇒ Object
-
#initialize ⇒ FileFinder
constructor
A new instance of FileFinder.
Constructor Details
#initialize ⇒ FileFinder
Returns a new instance of FileFinder.
13 14 |
# File 'lib/trop/file_finder.rb', line 13 def initialize end |
Class Method Details
.collect_dir_tree(path) ⇒ Object
164 165 166 167 |
# File 'lib/trop/file_finder.rb', line 164 def self.collect_dir_tree(path) finder = FileFinder.new finder.collect_dir_tree(path) end |
.collect_md_tree(path) ⇒ Object
159 160 161 162 |
# File 'lib/trop/file_finder.rb', line 159 def self.collect_md_tree(path) finder = FileFinder.new finder.collect_md_tree(path) end |
.collect_sorted_readme(path) ⇒ Object
154 155 156 157 |
# File 'lib/trop/file_finder.rb', line 154 def self.collect_sorted_readme(path) finder = FileFinder.new finder.collect_sorted_readme(File.(path)) end |
.my_gemspec_fffind(*path) ⇒ Object
169 170 171 172 |
# File 'lib/trop/file_finder.rb', line 169 def self.my_gemspec_fffind(*path) finder = FileFinder.new finder.collect_gem_tree(*path) end |
Instance Method Details
#collect_dir_tree(spath) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/trop/file_finder.rb', line 64 def collect_dir_tree(spath) @dirs = [] files = dffind(spath) return files end |
#collect_gem_tree(path) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/trop/file_finder.rb', line 71 def collect_gem_tree(path) files = [] if path.is_a? Array path.each {|s| files += fffind(s) } else files += fffind(path) end out=[] files.each do |f| f = f.delete_prefix('/home/werner/rails/trop/') next unless f.to_s.end_with?('.rb') out << f end return out end |
#collect_md_tree(spath) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/trop/file_finder.rb', line 130 def collect_md_tree(spath) @mds = [] files = fffind(spath) files.each do |page| page = Pathname.new(page) next if page.directory? fbase = page.basename.to_s.upcase if page.file? && fbase.include?('.MD') puts "Found : #{page.to_path}".cyan if $DEBUG @mds << page.to_s else Sh.info "skip: #{page.to_path}".blue if $DEBUG end end @mds end |
#collect_readme_md_tree(spath) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/trop/file_finder.rb', line 112 def collect_readme_md_tree(spath) @readmes = [] files = fffind(spath) files.each do |page| page = Pathname.new(page) next if page.directory? fbase = page.basename.to_s.upcase if page.file? && fbase.include?('README') && fbase.include?('.MD') puts "Found : #{page.to_path}".cyan if $DEBUG @readmes << page.to_s else Sh.info "skip: #{page.to_path}".blue if $DEBUG end end @readmes end |
#collect_sorted_readme(spath) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/trop/file_finder.rb', line 91 def collect_sorted_readme(spath) @readmes = [] files = fffind(spath) files.each do |page| page = Pathname.new(page) next if page.directory? fbase = page.basename.to_s.upcase if page.file? && fbase.include?('README') ##&& fbase.include?('.MD') puts "Found : #{page.to_path}".red if Sh.verbose? @readmes << page.to_s else Sh.info "skip: #{page.to_path}".blue if $DEBUG end end @readmes = @readmes.sort @readmes = @readmes.uniq res1, res2, res3 = filter_pages(@readmes) return res1, res2, res3 end |
#dffind(_path) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/trop/file_finder.rb', line 30 def dffind(_path) _path = Dir.getwd.to_s if _path.equal?('.') _path = File.(_path) @path = _path rule = FileFind.new( :ftype => 'directory', :follow => true, :path => _path.to_s ) tree = rule.find tree end |
#fffind(_path) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/trop/file_finder.rb', line 16 def fffind(_path) _path = Dir.getwd.to_s if _path.equal?('.') _path = File.(_path) @path = _path rule = FileFind.new( :ftype => 'file', :follow => true, :path => _path.to_s ) tree = rule.find tree end |
#filter_pages(pages) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/trop/file_finder.rb', line 44 def filter_pages(pages) tops = [] generics = [] contents = [] pages.each do |p| if p.start_with?(File.join(@path, 'doc/README.md')) tops << p elsif p.start_with?(File.join(@path, 'generic/doc/README.md')) tops << p elsif p.start_with?(File.join(@path, 'doc/')) tops << p elsif p.start_with?(File.join(@path, 'generic/')) generics << p else contents << p end end return tops, generics, contents end |