Class: SpecGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-pack/spec_generator.rb

Constant Summary collapse

ROOT_ATTRIBUTES =
%w[name version summary license authors homepage description social_media_url
docset_url documentation_url screenshots frameworks libraries requires_arc
deployment_target xcconfig pod_target_xcconfig user_target_xcconfig source vendored_frameworks
vendored_libraries resource_bundles resources preserve_paths cocoapods_version swift_versions].freeze
PLATFORM_ATTRIBUTES =
%w[frameworks libraries requires_arc xcconfig pod_target_xcconfig user_target_xcconfig].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_podspec, artifact_repo_url, zip_output_path, staged_sources) ⇒ SpecGenerator

Returns a new instance of SpecGenerator.



32
33
34
35
36
37
38
# File 'lib/cocoapods-pack/spec_generator.rb', line 32

def initialize(source_podspec, artifact_repo_url, zip_output_path, staged_sources)
  @podspec_path = source_podspec
  @artifact_repo_url = artifact_repo_url
  @zip_output_path = zip_output_path
  @staged_sources = staged_sources
  @platforms = []
end

Instance Attribute Details

#artifact_repo_urlObject (readonly)

Returns the value of attribute artifact_repo_url.



30
31
32
# File 'lib/cocoapods-pack/spec_generator.rb', line 30

def artifact_repo_url
  @artifact_repo_url
end

#platformsObject (readonly)

Returns the value of attribute platforms.



30
31
32
# File 'lib/cocoapods-pack/spec_generator.rb', line 30

def platforms
  @platforms
end

#podspec_pathObject (readonly)

Returns the value of attribute podspec_path.



30
31
32
# File 'lib/cocoapods-pack/spec_generator.rb', line 30

def podspec_path
  @podspec_path
end

#staged_sourcesObject (readonly)

Returns the value of attribute staged_sources.



30
31
32
# File 'lib/cocoapods-pack/spec_generator.rb', line 30

def staged_sources
  @staged_sources
end

Instance Method Details

#add_platform(platform, executable_name) ⇒ Object



55
56
57
# File 'lib/cocoapods-pack/spec_generator.rb', line 55

def add_platform(platform, executable_name)
  @platforms << [platform, executable_name]
end

#generateObject



51
52
53
# File 'lib/cocoapods-pack/spec_generator.rb', line 51

def generate
  Pod::Specification.from_string(generate_ruby_string, "#{@podspec_path.name}.podspec")
end

#generate_ruby_stringObject



40
41
42
43
44
45
46
47
48
49
# File 'lib/cocoapods-pack/spec_generator.rb', line 40

def generate_ruby_string
  root_attributes = hash_to_dsl(@podspec_path.attributes_hash.merge('source' => artifact_repo_hash), ROOT_ATTRIBUTES)
  sections = [root_attributes]
  sections << dependency_section
  sections.push(*platforms_sections)
  sections_str = sections.reject(&:empty?).map do |section|
    section.map { |lines| lines + "\n" }.join('')
  end.join("\n")
  "#{header}\n#{open}\n#{sections_str}#{close}\n"
end