Class: Ploy::Package

Inherits:
Object
  • Object
show all
Defined in:
lib/ploy/package.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bucket, deploy, branch, version) ⇒ Package

Returns a new instance of Package.



10
11
12
13
14
15
16
# File 'lib/ploy/package.rb', line 10

def initialize(bucket, deploy, branch, version)
  @deploy_name = deploy
  @branch = branch
  @version = version

  @store = Ploy::S3Storage.new(bucket)
end

Instance Attribute Details

#branchObject

Returns the value of attribute branch.



7
8
9
# File 'lib/ploy/package.rb', line 7

def branch
  @branch
end

#deploy_nameObject

Returns the value of attribute deploy_name.



6
7
8
# File 'lib/ploy/package.rb', line 6

def deploy_name
  @deploy_name
end

#versionObject

Returns the value of attribute version.



8
9
10
# File 'lib/ploy/package.rb', line 8

def version
  @version
end

Class Method Details

.from_metadata(bucket, meta) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/ploy/package.rb', line 53

def self.(bucket, meta)
  out = []
  meta.each do |k,v|
    out.push(self.new(bucket, v['name'], v['branch'], v['sha']))
  end
  return out
end

Instance Method Details

#blessObject



31
32
33
34
35
36
# File 'lib/ploy/package.rb', line 31

def bless
  @store.copy(
    location,
    Ploy::Util.remote_name(@deploy_name, @branch, @version, true)
  )
end

#check_new_versionObject



18
19
20
21
22
# File 'lib/ploy/package.rb', line 18

def check_new_version
  installed = `dpkg-query -W -f '${gitrev}' #{@deploy_name}`.chomp
  remote_v = @store.(location)['git_revision']
  return (installed != remote_v)
end

#installObject



24
25
26
27
28
29
# File 'lib/ploy/package.rb', line 24

def install
  Tempfile.open(['ploy', '.deb']) do |f|
    @store.get(location, f)
    system("dpkg -i #{f.path}")
  end
end

#locationObject



38
39
40
# File 'lib/ploy/package.rb', line 38

def location
  return Ploy::Util.remote_name(@deploy_name, @branch, @version)
end

#location_currentObject



41
42
43
# File 'lib/ploy/package.rb', line 41

def location_current
  return Ploy::Util.remote_name(@deploy_name, @branch, 'current')
end

#make_currentObject



49
50
51
# File 'lib/ploy/package.rb', line 49

def make_current
  @store.copy(location, location_current)
end

#upload(path) ⇒ Object



45
46
47
# File 'lib/ploy/package.rb', line 45

def upload(path)
  @store.put(path, location, {'git_revision' => @version})
end