Class: Fui::Finder
- Inherits:
-
Object
- Object
- Fui::Finder
- Defined in:
- lib/fui/finder.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #headers ⇒ Object
-
#initialize(path) ⇒ Finder
constructor
A new instance of Finder.
- #references(&block) ⇒ Object
- #unused_references(&block) ⇒ Object
Constructor Details
#initialize(path) ⇒ Finder
Returns a new instance of Finder.
5 6 7 8 |
# File 'lib/fui/finder.rb', line 5 def initialize(path) @path = File.(path) raise Errno::ENOENT.new(path) unless Dir.exists?(@path) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/fui/finder.rb', line 3 def path @path end |
Instance Method Details
#headers ⇒ Object
10 11 12 |
# File 'lib/fui/finder.rb', line 10 def headers @headers ||= Finder.find(path) { |path| Header.header?(path) }.collect { |path| Header.new(path) } end |
#references(&block) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/fui/finder.rb', line 14 def references(&block) @references ||= begin references = {} headers.each do |header| references[header] = [] end Find.find(path) do |path| next unless [".m", ".h", ".pch"].include?(File.extname(path)) && File.ftype(path) == "file" File.open(path) do |file| filename = File.basename(path) yield path if block_given? headers.each do |header| filename_without_extension = File.basename(path, File.extname(path)) references[header] << path if filename_without_extension != header.filename_without_extension && File.read(file).include?("#import \"#{header.filename}\"") end end end references end end |
#unused_references(&block) ⇒ Object
35 36 37 |
# File 'lib/fui/finder.rb', line 35 def unused_references(&block) @unused_references ||= references(&block).select { |k, v| v.count == 0 } end |