class StoryboardLint::SourceScanner
Public Class Methods
new(src_root, matcher, additional_sources = nil)
click to toggle source
# File lib/storyboardlint.rb, line 89 def initialize(src_root, matcher, additional_sources = nil) if !File.directory?(src_root) raise ArgumentError, "The directory '#{src_root}' does not exist." end if !matcher raise ArgumentError, "The matcher cannot be nil." end @additional_sources = additional_sources @matcher = matcher @src_root = src_root @scan_performed = false end
Public Instance Methods
class_names()
click to toggle source
# File lib/storyboardlint.rb, line 152 def class_names scan_files @class_names end
reuse_ids()
click to toggle source
# File lib/storyboardlint.rb, line 147 def reuse_ids scan_files @reuse_ids end
segue_ids()
click to toggle source
# File lib/storyboardlint.rb, line 137 def segue_ids scan_files @segue_ids end
source_files()
click to toggle source
# File lib/storyboardlint.rb, line 104 def source_files return @source_files if @source_files # find all *.h, *.c, *.m and *.mm files match_string = "**/*.{h,c,m,mm}" @source_files = Dir.glob(File.join(@src_root, match_string)) if @additional_sources && @additional_sources.size > 0 @additional_sources.each do |source_path| absolute_path = '' if source_path.start_with?("/") #absolute path absolute_path = source_path else #relative to src_root absolute_path = File.join(@src_root, source_path) end if File.directory?(absolute_path) @source_files += Dir.glob(File.join(absolute_path, match_string)) else puts "warning: additional source directory '#{absolute_path}' does not exist!" end end end if @source_files and @source_files.size > 0 @source_files.select! {|sf| File.file?(sf)} end @source_files end
storyboard_ids()
click to toggle source
# File lib/storyboardlint.rb, line 142 def storyboard_ids scan_files @storyboard_ids end
Private Instance Methods
scan_files()
click to toggle source
# File lib/storyboardlint.rb, line 159 def scan_files if !@scan_performed @class_names ||= [] @segue_ids ||= [] @storyboard_ids ||= [] @reuse_ids ||= [] source_files.each do |source_file| File.readlines(source_file, :encoding => 'UTF-8').each_with_index do |line, idx| # class names line.scan(@matcher.class_regex).each do |match| @class_names << {:file => source_file, :line => idx + 1, :class_name => match[0]} end # segue ids line.scan(@matcher.segue_id_regex_source).each do |match| @segue_ids << {:file => source_file, :line => idx + 1, :id => match[0]} end # storyboard ids line.scan(@matcher.storyboard_id_regex_source).each do |match| @storyboard_ids << {:file => source_file, :line => idx + 1, :id => match[0]} end # reuse ids line.scan(@matcher.reuse_id_regex_source).each do |match| @reuse_ids << {:file => source_file, :line => idx + 1, :id => match[0]} end end end @scan_performed = true end end