Class: StoryboardLint::StoryboardScanner

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

Instance Method Summary collapse

Constructor Details

#initialize(src_root) ⇒ StoryboardScanner



12
13
14
15
# File 'lib/storyboardlint.rb', line 12

def initialize(src_root)
  @src_root = src_root
  @scan_performed = false    
end

Instance Method Details

#custom_class_namesObject



63
64
65
66
# File 'lib/storyboardlint.rb', line 63

def custom_class_names
  scan_files
  @custom_class_names
end

#reuse_idsObject



58
59
60
61
# File 'lib/storyboardlint.rb', line 58

def reuse_ids
  scan_files
  @reuse_ids
end

#scan_filesObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/storyboardlint.rb', line 24

def scan_files
  if !@scan_performed
    @segue_ids ||= []
    @storyboard_ids ||= []
    @reuse_ids ||= []
    @custom_class_names = []

    storyboard_files.each do |sb_file|
      sb_source = File.open(sb_file)
      doc = Nokogiri::XML(sb_source)
      doc.xpath('//segue').each do |element|
        seg_id = element.attr('identifier')
        @segue_ids << {:file => sb_file, :id => seg_id.to_s} if seg_id
      end

      @storyboard_ids += doc.xpath("//@storyboardIdentifier").to_a.map {|match| {:file => sb_file, :id => match.to_s}}
      @reuse_ids += doc.xpath("//@reuseIdentifier").to_a.map {|match| {:file => sb_file, :id => match.to_s}}
      @custom_class_names += doc.xpath("//@customClass").to_a.map {|match| {:file => sb_file, :class_name => match.to_s}}
    end
    
    @scan_performed = true
  end
end

#segue_idsObject



48
49
50
51
# File 'lib/storyboardlint.rb', line 48

def segue_ids
  scan_files
  @segue_ids
end

#storyboard_filesObject



17
18
19
20
21
22
# File 'lib/storyboardlint.rb', line 17

def storyboard_files
  return @sb_files if @sb_files
  
  # find all storyboard files...
  @sb_files = Dir.glob(File.join(@src_root, "**/*.storyboard"))
end

#storyboard_idsObject



53
54
55
56
# File 'lib/storyboardlint.rb', line 53

def storyboard_ids
  scan_files
  @storyboard_ids
end