Class: Xcode::Project::Packer

Inherits:
Object
  • Object
show all
Defined in:
lib/xcode/project/packer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ Packer

Returns a new instance of Packer.



8
9
10
# File 'lib/xcode/project/packer.rb', line 8

def initialize(project)
  @project = project
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project.



7
8
9
# File 'lib/xcode/project/packer.rb', line 7

def project
  @project
end

Instance Method Details

#buildObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/xcode/project/packer.rb', line 39

def build
  arguments = %w[xcodebuild]
  arguments += %W[-project #{project.path}]
  arguments += %W[-configuration #{project.configuration}]
  arguments += %w[-nodependencies]
  arguments += project.variables.map{ |key, value| "#{key}=#{value}" }
  arguments += %w[clean build]

  sh *arguments
end

#packObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/xcode/project/packer.rb', line 50

def pack
  if pack_path.exist?
    abort "#{pack_path} already exists"
  else
    build

    arguments = %W[tar -cjf #{pack_path.expand_path}]
    arguments += product_names

    Dir.chdir products_dir do
      sh *arguments
    end
  end
end

#pack_descriptionObject



20
21
22
# File 'lib/xcode/project/packer.rb', line 20

def pack_description
  @pack_description ||= "#{project.name} v#{project.version}"
end

#pack_pathObject



12
13
14
15
16
17
18
# File 'lib/xcode/project/packer.rb', line 12

def pack_path
  @pack_path ||= begin
    pkg_dir = Pathname('pkg')
    pkg_dir.mkpath
    pkg_dir + "#{project.name}-#{project.version}.tbz"
  end
end

#product_namesObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/xcode/project/packer.rb', line 24

def product_names
  [].tap do |names|
    objects = project.config.root['objects']
    objects.each do |_, object|
      if reference = object['productReference']
        names << objects[reference]['path']
      end
    end
  end
end

#products_dirObject



35
36
37
# File 'lib/xcode/project/packer.rb', line 35

def products_dir
  Pathname('build') + project.configuration
end

#releaseObject



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/xcode/project/packer.rb', line 65

def release
  unless `git remote -v` =~ /git@github\.com:([^\/]+)\/(.+?)\.git/
    abort 'can\'t find github remote'
  else
    , repos = $1, $2
    token = Keychain.items.find{ |item| item.label[/^github.com/] && item. == "#{}/token" }.password

    pack

    uploader = Net::GitHub::Upload.new(:login => , :token => token)
    uploader.upload(:repos => repos, :file => pack_path.to_s, :description => pack_description)
  end
end