Class: Fui::Finder

Inherits:
Object
  • Object
show all
Defined in:
lib/fui/finder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Finder

Returns a new instance of Finder.

Raises:

  • (Errno::ENOENT)


5
6
7
8
# File 'lib/fui/finder.rb', line 5

def initialize(path)
  @path = File.expand_path(path)
  raise Errno::ENOENT.new(path) unless Dir.exists?(@path)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/fui/finder.rb', line 3

def path
  @path
end

Instance Method Details

#headersObject



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
# 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 File.ftype(path) == "file"
      if [".m", ".h", ".pch"].include?(File.extname(path))
        process_code references, path, &block
      elsif [".storyboard", ".xib"].include?(File.extname(path))
        process_xml references, path, &block
      end
    end
    references
  end
end

#unused_references(&block) ⇒ Object



32
33
34
# File 'lib/fui/finder.rb', line 32

def unused_references(&block)
  @unused_references ||= references(&block).select { |k, v| v.count == 0 }
end