class Pod::SpecBuilder

Public Class Methods

new(spec, source, embedded, dynamic) click to toggle source
# File lib/cocoapods-packager/spec_builder.rb, line 4
def initialize(spec, source, embedded, dynamic)
  @spec = spec
  name = spec.attributes_hash['name']
  version = spec.attributes_hash['version']
  @source = source.nil? ? "{ :http => 'https://10.0.0.0/staticpods/#{name}/#{name}-#{version}.zip' }" : source
  @embedded = embedded
  @dynamic = dynamic
  @platform = nil
end

Public Instance Methods

framework_path() click to toggle source
# File lib/cocoapods-packager/spec_builder.rb, line 14
def framework_path
  if @embedded
    @spec.name + '.embeddedframework' + '/' + @spec.name + '.framework'
  else
    @spec.name + '.framework'
  end
end
get_all_dependenices(plat) click to toggle source
# File lib/cocoapods-packager/spec_builder.rb, line 148
def get_all_dependenices(plat)
  depen = @spec.all_dependencies(plat)
  depen = depen.map {|den| den.name}
  depen = depen.select {|de| !de.include?('/')}
  depen
end
get_all_type(type) click to toggle source
# File lib/cocoapods-packager/spec_builder.rb, line 50
def get_all_type(type)
  subspecs = subspec_json
  all_frame = Set.new
  if subspecs.length > 0
    subspecs.each do |subspec|
      subspec = JSON.parse(subspec)
      if !subspec
        next
      end
      df = subspec[type]
      if df 
        if df.class == String
          all_frame.add(df)
        elsif df.class == Array
          all_frame.merge(df)
        end
      end
      plat = subspec['ios']
      if plat
        if plat.class == Hash
          plat_f = plat[type]
          if plat_f
            if plat_f.class == String
              all_frame.add(plat_f)
            elsif plat_f.class == Array
              all_frame.merge(plat_f)
            end
          end
        end
      end
    end
  end
  spec_json = JSON.parse(get_spec_json)
  dfm = spec_json[type]
  if dfm
    if dfm.class == String
      all_frame.add(dfm)
    elsif dfm.class == Array
      all_frame.merge(dfm)
    end
  end
  if !dfm
    return all_frame
  end
  if dfm.class != Hash
    return all_frame
  end
  plat = dfm['ios']
  if plat
    if plat.class == Hash
      plat_f = plat[type]
      if plat_f
        if plat_f.class == String
          all_frame.add(plat_f)
        elsif plat_f.class == Array
          all_frame.merge(plat_f)
        end
      end
    end
  end
  # puts "get all type --> #{type} value --> #{all_frame}"
  return all_frame
end
get_platform() click to toggle source
# File lib/cocoapods-packager/spec_builder.rb, line 136
def get_platform
  platform_str = ''
  platform = process_platform_hash
  if platform
    if platform['ios']
      platform_str = "  s.platform = :ios, '#{platform['ios']}' \n"
    else
      platform_str = "  s.platform = :ios"
    end
  end
  platform_str
end
get_resource() click to toggle source
# File lib/cocoapods-packager/spec_builder.rb, line 116
def get_resource
 return get_spec_json.include?('resource_bundles') || get_spec_json.include?('resource') || get_spec_json.include?('resources') || get_spec_json.include?('resource_bundle')
end
get_spec_json() click to toggle source
# File lib/cocoapods-packager/spec_builder.rb, line 113
def get_spec_json
  return @spec.to_pretty_json
end
process_platform_hash() click to toggle source
# File lib/cocoapods-packager/spec_builder.rb, line 119
def process_platform_hash
  case value = @spec.attributes_hash['platforms']
  when String
    { value => nil }
  when Array
    result = {}
    value.each do |a_value|
      result[a_value] = nil
    end
    result
  when Hash
    value
  else
    {}
  end
end
spec_close() click to toggle source
# File lib/cocoapods-packager/spec_builder.rb, line 202
def spec_close
  "end\n"
end
spec_metadata() click to toggle source
# File lib/cocoapods-packager/spec_builder.rb, line 154
def spec_metadata
  spec = spec_header
  spec += get_platform
  frames = get_all_type('frameworks')
  if frames.length > 0
    spec += '  s.frameworks = '
    frames.each do |val|
      spec += "'#{val}',"
    end
    spec = spec.delete_suffix(',')
    spec += "\n"
  end
  framework = get_all_type('framework')
  if framework.length > 0
    framework.each do |val|
      spec += "  s.framework = #{val}\n"
    end
  end
  libs = get_all_type('libraries')
  if libs.length > 0
    spec += "  s.libraries = "
    libs.each do |val|
      spec += "'#{val}',"
    end
    spec = spec.delete_suffix(',')
    spec += "\n"
  end
  library = get_all_type('library')
  if library.length > 0
    library.each do |val|
      spec += "  s.library = #{val} \n"
    end
  end
  dependices = get_all_dependenices(@platform)
  if dependices.length > 0
    dependices.each do |val|
      spec += "  s.dependency '#{val}' \n"
    end
    spec += "\n"
  end
  
  res = get_resource
  if res
    spec += "  s.resources = 'ios/#{framework_path}/Resources/#{@spec.name}.bundle' \n"
  end
  spec
end
spec_platform(platform) click to toggle source
# File lib/cocoapods-packager/spec_builder.rb, line 22
    def spec_platform(platform)
      fwk_base = platform.name.to_s + '/' + framework_path
      spec = <<RB
  s.#{platform.name}.deployment_target    = '#{platform.deployment_target}'
  s.#{platform.name}.vendored_framework   = '#{fwk_base}'
RB

      %w(requires_arc xcconfig).each do |attribute|
        attributes_hash = @spec.attributes_hash[platform.name.to_s]
        next if attributes_hash.nil?
        value = attributes_hash[attribute]
        next if value.nil?

        value = "'#{value}'" if value.class == String
        spec += "  s.#{platform.name}.#{attribute} = #{value}\n"
      end
      @platform = platform
      spec
    end
subspec_json() click to toggle source
# File lib/cocoapods-packager/spec_builder.rb, line 42
def subspec_json
  if @spec.subspecs.length < 1
    return []
  end
  new_sub = @spec.subspecs.map {|spec| spec.to_pretty_json}
  return new_sub
end

Private Instance Methods

spec_header() click to toggle source
# File lib/cocoapods-packager/spec_builder.rb, line 208
def spec_header
  spec = "Pod::Spec.new do |s|\n"

  %w(name version summary license authors homepage description social_media_url documentation_url requires_arc
     deployment_target xcconfig).each do |attribute|
    value = @spec.attributes_hash[attribute]
    next if value.nil?
    value = value.dump if value.class == String
    spec += "  s.#{attribute} = #{value}\n"
  end

  spec + "  s.source = #{@source}\n\n"
end