Class: Xcake::PathClassifier

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

Overview

This class handles classifing the files and how Xcake should handle them.

Constant Summary collapse

EXTENSION_MAPPINGS =
{
  PBXFrameworksBuildPhase: %w(.a .dylib .so .framework).freeze,
  PBXHeadersBuildPhase: %w(.h .hpp).freeze,
  PBXSourcesBuildPhase: %w(.c .m .mm .cpp .cc .swift .xcdatamodeld .intentdefinition .java).freeze,
  PBXResourcesBuildPhase: %w(.xcassets).freeze
}.freeze

Class Method Summary collapse

Class Method Details

.classification_for_path(path) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/xcake/path_classifier.rb', line 29

def self.classification_for_path(path)
  classification = EXTENSION_MAPPINGS.detect do |_key, ext_group|
    ext_group.any? { |ext| File.extname(path) == ext }
  end

  return :PBXResourcesBuildPhase if classification.nil?

  classification.first
end

.classified?(path) ⇒ Boolean (private)

Returns:

  • (Boolean)


65
66
67
# File 'lib/xcake/path_classifier.rb', line 65

def classified?(path)
  EXTENSION_MAPPINGS.values.flatten.any? { |ext| File.extname(path) == ext }
end

.inside_classified_container?(path) ⇒ Boolean (private)

Returns:

  • (Boolean)


51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/xcake/path_classifier.rb', line 51

def inside_classified_container?(path)
  components = path.split('/')

  classified_component_index = components.index do |c|
    classified?(c)
  end

  if !classified_component_index.nil?
    classified_component_index < (components.length - 1)
  else
    false
  end
end

.locale_container?(path) ⇒ Boolean (private)

Returns:

  • (Boolean)


46
47
48
49
# File 'lib/xcake/path_classifier.rb', line 46

def locale_container?(path)
  components = path.split('/')
  File.extname(components.last) == '.lproj'
end

.should_create_build_phase_for_classification?(classification) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/xcake/path_classifier.rb', line 39

def self.should_create_build_phase_for_classification?(classification)
  classification != :PBXHeadersBuildPhase
end

.should_include_path?(path) ⇒ Boolean

Note:

This should be overidden

by subclasses.

into the project

Parameters:

Returns:

  • (Boolean)

    true if classifier thinks the path should be included



22
23
24
25
26
27
# File 'lib/xcake/path_classifier.rb', line 22

def self.should_include_path?(path)
  return false if locale_container?(path)
  return false if inside_classified_container?(path)

  true
end