Class: ProjectGen::ProjectGenerator

Inherits:
Object
  • Object
show all
Includes:
Pod::Config::Mixin, Helper, SwiftModule
Defined in:
lib/cocoapods-project-gen/gen/project_gen.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helper

app_target_name

Methods included from SwiftModule

#add_swift_library_compatibility_header, #derived_swift_version, #dot_swift_version, #validate_swift_version

Constructor Details

#initialize(source_urls, platforms = []) ⇒ ProjectGenerator

Initialize a new instance

Parameters:

  • source_urls (Array<String>)

    the Source URLs to use in creating a Podfile.

  • platforms (Array<String>) (defaults to: [])

    the platforms to lint.



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/cocoapods-project-gen/gen/project_gen.rb', line 136

def initialize(source_urls, platforms = [])
  @source_urls = source_urls.map { |url| config.sources_manager.source_with_name_or_url(url) }.map(&:url)
  @platforms = platforms.map do |platform|
    result =  case platform.to_s.downcase
              # Platform doesn't recognize 'macos' as being the same as 'osx' when initializing
              when 'macos' then Pod::Platform.macos
              else Pod::Platform.new(platform, nil)
              end
    unless Constants.valid_platform?(result)
      raise Informative, "Unrecognized platform `#{platform}`. Valid platforms: #{VALID_PLATFORMS.join(', ')}"
    end

    result
  end
  @allow_warnings = true
  @use_frameworks = true
  @use_latest = true
end

Instance Attribute Details

#allow_warningsBoolean

Returns Whether the validator should fail on warnings, or only on errors.

Returns:

  • (Boolean)

    Whether the validator should fail on warnings, or only on errors.



49
50
51
# File 'lib/cocoapods-project-gen/gen/project_gen.rb', line 49

def allow_warnings
  @allow_warnings
end

#configurationObject

Returns configuration.

Returns:

  • configuration



86
87
88
# File 'lib/cocoapods-project-gen/gen/project_gen.rb', line 86

def configuration
  @configuration
end

#external_podspecsString

Returns A glob for podspecs to be used during building of the local Podfile via :podspec.

Returns:

  • (String)

    A glob for podspecs to be used during building of the local Podfile via :podspec.



75
76
77
# File 'lib/cocoapods-project-gen/gen/project_gen.rb', line 75

def external_podspecs
  @external_podspecs
end

#fail_fastBoolean

Returns whether the linter should fail as soon as the first build variant causes an error. Helpful for i.e. multi-platforms specs, specs with subspecs.

Returns:

  • (Boolean)

    whether the linter should fail as soon as the first build variant causes an error. Helpful for i.e. multi-platforms specs, specs with subspecs.



38
39
40
# File 'lib/cocoapods-project-gen/gen/project_gen.rb', line 38

def fail_fast
  @fail_fast
end

#include_podspecsString

Returns A glob for podspecs to be used during building of the local Podfile via :path.

Returns:

  • (String)

    A glob for podspecs to be used during building of the local Podfile via :path.



70
71
72
# File 'lib/cocoapods-project-gen/gen/project_gen.rb', line 70

def include_podspecs
  @include_podspecs
end

#localBoolean Also known as: local?

Returns whether the validation should be performed against the root of the podspec instead to its original source.

Returns:

  • (Boolean)

    whether the validation should be performed against the root of the podspec instead to its original source.



44
45
46
# File 'lib/cocoapods-project-gen/gen/project_gen.rb', line 44

def local
  @local
end

#no_cleanBoolean

Returns whether the linter should not clean up temporary files for inspection.

Returns:

  • (Boolean)

    whether the linter should not clean up temporary files for inspection.



32
33
34
# File 'lib/cocoapods-project-gen/gen/project_gen.rb', line 32

def no_clean
  @no_clean
end

#only_subspecsString

Returns name of the subspec to check, if nil all subspecs are checked.

Returns:

  • (String)

    name of the subspec to check, if nil all subspecs are checked.



53
54
55
# File 'lib/cocoapods-project-gen/gen/project_gen.rb', line 53

def only_subspecs
  @only_subspecs
end

#resultsObject (readonly)

!@group results



16
17
18
# File 'lib/cocoapods-project-gen/gen/project_gen.rb', line 16

def results
  @results
end

#source_urlsArray<String> (readonly)

Returns an array of source URLs used to create the Podfile used in the linting process.

Returns:

  • (Array<String>)

    an array of source URLs used to create the Podfile used in the linting process



82
83
84
# File 'lib/cocoapods-project-gen/gen/project_gen.rb', line 82

def source_urls
  @source_urls
end

#swift_versionString

--swift-version parameter during validation.

Returns:

  • (String)

    The SWIFT_VERSION that should be used to validate the pod. This is set by passing the



28
29
30
# File 'lib/cocoapods-project-gen/gen/project_gen.rb', line 28

def swift_version
  @swift_version
end

#use_frameworksBoolean

Returns Whether frameworks should be used for the installation.

Returns:

  • (Boolean)

    Whether frameworks should be used for the installation.



57
58
59
# File 'lib/cocoapods-project-gen/gen/project_gen.rb', line 57

def use_frameworks
  @use_frameworks
end

#use_latestObject

When multiple dependencies with different sources, use latest.



23
24
25
# File 'lib/cocoapods-project-gen/gen/project_gen.rb', line 23

def use_latest
  @use_latest
end

#use_modular_headersBoolean

Returns Whether modular headers should be used for the installation.

Returns:

  • (Boolean)

    Whether modular headers should be used for the installation.



61
62
63
# File 'lib/cocoapods-project-gen/gen/project_gen.rb', line 61

def use_modular_headers
  @use_modular_headers
end

#use_static_frameworksBoolean

Returns Whether static frameworks should be used for the installation.

Returns:

  • (Boolean)

    Whether static frameworks should be used for the installation.



65
66
67
# File 'lib/cocoapods-project-gen/gen/project_gen.rb', line 65

def use_static_frameworks
  @use_static_frameworks
end

Class Method Details

.new_from_local(podspecs = [], source_urls = [Pod::TrunkSource::TRUNK_REPO_URL], platforms = [], product_type = :framework, configuration = :release, swift_version = nil, use_modular_headers: false) ⇒ Object

Initialize a new instance

Parameters:

  • podspecs (Array<Specification, Pathname, String>) (defaults to: [])

    the Specifications or the paths of the podspec files to used.

  • source_urls (Array<String>) (defaults to: [Pod::TrunkSource::TRUNK_REPO_URL])

    the Source URLs to use in creating a Podfile.

  • platforms (Array<String>) (defaults to: [])

    the platforms to used.

  • either (Symbol)

    :framework or :static_library, depends on #build_as_framework?.

  • The (Symbol)

    name of the build configuration.

  • the (String)

    SWIFT_VERSION within the .swift-version file or nil.

  • Whether (Boolean)

    modular headers should be used for the installation.



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/cocoapods-project-gen/gen/project_gen.rb', line 112

def self.new_from_local(podspecs = [], source_urls = [Pod::TrunkSource::TRUNK_REPO_URL], platforms = [], product_type = :framework, configuration = :release, swift_version = nil, use_modular_headers: false)
  generator = new(source_urls, platforms)
  generator.local = true
  generator.no_subspecs = true
  generator.only_subspecs = nil
  generator.no_clean       = false
  generator.allow_warnings = true
  generator.use_frameworks = product_type == :dynamic_framework
  generator.use_static_frameworks = product_type == :framework
  generator.include_podspecs = podspecs
  generator.configuration = configuration
  generator.use_modular_headers = use_modular_headers
  generator.swift_version = swift_version
  generator
end

Instance Method Details

#generate!(work_dir, &block) ⇒ Object

Create app project

Parameters:

  • dir (String, Pathname)

    the temporary directory used by the Gen.

  • &block (block<platforms, pod_targets, valid>)

    the block to execute inside the lock.



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/cocoapods-project-gen/gen/project_gen.rb', line 161

def generate!(work_dir, &block)
  @project_gen_dir = Pathname(work_dir)
  @results = Results.new
  unless config.silent?
    podspecs.each do |spec|
      subspecs = determine_subspecs[spec]
      if subspecs && !subspecs.empty?
        subspecs.each { |s| Results.puts " -> #{s}\r\n" }
      else
        Results.puts " -> #{spec.name}\r\n"
      end
    end
  end
  $stdout.flush
  perform_linting
  platforms, pod_targets, valid = install
  @results.print_results
  block.call(platforms, pod_targets, @clean, @fail_fast) if !block.nil? && valid
end

#project_gen_dirPathname

Returns the temporary directory used by the linter.

Returns:

  • (Pathname)

    the temporary directory used by the linter.



183
184
185
# File 'lib/cocoapods-project-gen/gen/project_gen.rb', line 183

def project_gen_dir
  @project_gen_dir ||= Pathname(Dir.mktmpdir(['cocoapods-project-gen-', "-#{spec.name}"]))
end