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, options = {}) ⇒ Finder

Returns a new instance of Finder.

Raises:

  • (Errno::ENOENT)


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

def initialize(path, options = {})
  @path = File.expand_path(path)
  @options = options
  raise Errno::ENOENT, path unless Dir.exist?(@path)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#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



11
12
13
# File 'lib/fui/finder.rb', line 11

def headers
  @headers ||= Finder.find(path) { |path| Header.header?(path) }.collect { |path| Header.new(path) }
end

#references(&block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fui/finder.rb', line 15

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



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

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