Class: Fui::Finder

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

Overview

A class to find various things in an Objective C project.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, options = {}) ⇒ Finder

Returns a new instance of Finder.

Raises:

  • (Errno::ENOENT)


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

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.



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

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#bridging_headersObject



16
17
18
# File 'lib/fui/finder.rb', line 16

def bridging_headers
  @bridging_headers ||= find(path) { |path| Project.project?(path) }.collect { |path| Project.new(path).bridging_headers(options[:verbose]) }
end

#headersObject



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

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

#ignoresObject



20
21
22
23
24
25
26
27
28
# File 'lib/fui/finder.rb', line 20

def ignores
  return unless options['ignore-path']

  @ignores ||= options['ignore-path'].map do |i|
    raise Errno::ENOENT, i unless Dir.exist?(i)

    Pathname(i)
  end
end

#references(&block) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fui/finder.rb', line 30

def references(&block)
  @references ||= begin
    references = {}
    headers.each do |header|
      references[header] = []
    end
    Find.find(path) do |path|
      if ['.m', '.mm', '.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



47
48
49
# File 'lib/fui/finder.rb', line 47

def unused_references(&block)
  @unused_references ||= references(&block).select { |k, v| v.count.zero? && !bridging_headers.include?(k.filename) }
end