Class: XCRes::Analyzer
- Inherits:
-
Object
- Object
- XCRes::Analyzer
- Includes:
- FileHelper
- Defined in:
- lib/xcres/analyzer/analyzer.rb
Overview
An Analyzer
scans the project for references, which should be included in the output file.
Direct Known Subclasses
AggregateAnalyzer, ResourcesAnalyzer::BaseResourcesAnalyzer, StringsAnalyzer
Instance Attribute Summary collapse
-
#exclude_file_patterns ⇒ Array<String>
The exclude file patterns.
-
#logger ⇒ Logger
The logger.
-
#options ⇒ Hash
The options passed to the sections.
-
#sections ⇒ Array<Section>
readonly
The built sections.
-
#target ⇒ PBXNativeTarget
readonly
The application target of the #project to analyze.
Instance Method Summary collapse
-
#analyze ⇒ Array<Section>
Analyze the project.
-
#filter_exclusions(file_paths) ⇒ Object
Apply the configured exclude file patterns to a list of files.
-
#find_file_refs_by_extname(extname) ⇒ Array<PBXFileReference>
Discover all references to files with a specific extension in project, which belong to a resources build phase of an application target.
-
#initialize(target = nil, options = {}) ⇒ Analyzer
constructor
Initialize a new analyzer.
-
#is_file_ref_included_in_application_target?(file_ref) ⇒ Bool
Checks if a file ref is included in any resources build phase of any of the application targets of the #project.
-
#new_section(name, data, options = {}) ⇒ XCRes::Section
Create a new
Section
. -
#project ⇒ Xcodeproj::Project
Return the Xcode project to analyze.
-
#resources_files ⇒ Array<PBXFileReference>
Find files in resources build phases of application targets.
Methods included from FileHelper
Constructor Details
#initialize(target = nil, options = {}) ⇒ Analyzer
Initialize a new analyzer
43 44 45 46 47 48 |
# File 'lib/xcres/analyzer/analyzer.rb', line 43 def initialize(target=nil, ={}) @target = target @sections = [] @exclude_file_patterns = [] @options = end |
Instance Attribute Details
#exclude_file_patterns ⇒ Array<String>
Returns the exclude file patterns.
27 28 29 |
# File 'lib/xcres/analyzer/analyzer.rb', line 27 def exclude_file_patterns @exclude_file_patterns end |
#logger ⇒ Logger
Returns the logger.
31 32 33 |
# File 'lib/xcres/analyzer/analyzer.rb', line 31 def logger @logger end |
#options ⇒ Hash
Returns the options passed to the sections.
23 24 25 |
# File 'lib/xcres/analyzer/analyzer.rb', line 23 def @options end |
#sections ⇒ Array<Section> (readonly)
Returns the built sections.
19 20 21 |
# File 'lib/xcres/analyzer/analyzer.rb', line 19 def sections @sections end |
#target ⇒ PBXNativeTarget (readonly)
Returns the application target of the #project to analyze.
15 16 17 |
# File 'lib/xcres/analyzer/analyzer.rb', line 15 def target @target end |
Instance Method Details
#analyze ⇒ Array<Section>
Analyze the project
55 56 57 |
# File 'lib/xcres/analyzer/analyzer.rb', line 55 def analyze @sections = @sections.compact.reject { |s| s.items.nil? || s.items.empty? } end |
#filter_exclusions(file_paths) ⇒ Object
Apply the configured exclude file patterns to a list of files
92 93 94 95 96 |
# File 'lib/xcres/analyzer/analyzer.rb', line 92 def filter_exclusions file_paths file_paths.reject do |path| exclude_file_patterns.any? { |pattern| File.fnmatch("#{pattern}", path) || File.fnmatch("**/#{pattern}", path) } end end |
#find_file_refs_by_extname(extname) ⇒ Array<PBXFileReference>
Discover all references to files with a specific extension in project, which belong to a resources build phase of an application target.
107 108 109 110 111 112 |
# File 'lib/xcres/analyzer/analyzer.rb', line 107 def find_file_refs_by_extname(extname) project.files.select do |file_ref| File.extname(file_ref.path) == extname \ && is_file_ref_included_in_application_target?(file_ref) end end |
#is_file_ref_included_in_application_target?(file_ref) ⇒ Bool
Checks if a file ref is included in any resources build phase of any of the application targets of the #project.
122 123 124 |
# File 'lib/xcres/analyzer/analyzer.rb', line 122 def is_file_ref_included_in_application_target?(file_ref) resources_files.include?(file_ref) end |
#new_section(name, data, options = {}) ⇒ XCRes::Section
Create a new Section
.
80 81 82 |
# File 'lib/xcres/analyzer/analyzer.rb', line 80 def new_section(name, data, ={}) XCRes::Section.new(name, data, self..merge()) end |
#project ⇒ Xcodeproj::Project
Return the Xcode project to analyze
63 64 65 |
# File 'lib/xcres/analyzer/analyzer.rb', line 63 def project target.project end |
#resources_files ⇒ Array<PBXFileReference>
Find files in resources build phases of application targets
130 131 132 133 134 135 136 137 138 |
# File 'lib/xcres/analyzer/analyzer.rb', line 130 def resources_files target.resources_build_phase.files.map do |build_file| if build_file.file_ref.is_a?(Xcodeproj::Project::Object::PBXGroup) build_file.file_ref.recursive_children else [build_file.file_ref] end end.flatten.compact end |