Class: Vx::Aptly::Package

Inherits:
Object
  • Object
show all
Extended by:
Mixin::Capture, Common::Spawn
Includes:
Mixin::Capture
Defined in:
lib/vx/aptly/package.rb

Defined Under Namespace

Classes: AddResult

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixin::Capture

capture

Constructor Details

#initialize(params = {}) ⇒ Package

Returns a new instance of Package.



21
22
23
24
25
26
27
28
# File 'lib/vx/aptly/package.rb', line 21

def initialize(params = {})
  @attributes = {}
  params.each do |k,v|
    if self.respond_to?(:"#{k}=")
      self.public_send(:"#{k}=", v)
    end
  end
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



19
20
21
# File 'lib/vx/aptly/package.rb', line 19

def attributes
  @attributes
end

#errorObject

Returns the value of attribute error.



19
20
21
# File 'lib/vx/aptly/package.rb', line 19

def error
  @error
end

#noticeObject

Returns the value of attribute notice.



19
20
21
# File 'lib/vx/aptly/package.rb', line 19

def notice
  @notice
end

Class Method Details

.add(repo, filename, filepath) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/vx/aptly/package.rb', line 83

def add(repo, filename, filepath)
  new_filepath = Dir.tmpdir + "/#{filename}"
  FileUtils.cp filepath, new_filepath

  line = "aptly repo add #{repo.name} #{new_filepath}"
  rs   = AddResult.new
  begin
    capture line do |re|
      rs.notice = "The command '#{line}' was successfuly finished with output:\n"
      rs.notice << re
    end
  rescue AptlyCommandError => e
    rs.error  = e
  end
  rs
end

.all(repo) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/vx/aptly/package.rb', line 74

def all(repo)
  capture "aptly repo search #{repo.name} 'Name'" do |re|
    re.lines.inject([]) do |a, line|
      a << find(line.strip)
      a
    end.sort_by(&:id)
  end
end

.find(name) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/vx/aptly/package.rb', line 58

def find(name)
  capture "aptly package show #{name}" do |re|
    package = new(package: name)

    re.lines.each do |line|
      key, value = line.split(":").map(&:strip)
      key_name = key.gsub(/[^a-zA-Z]/, ' ').gsub(/ +/, '_').downcase
      if package.respond_to?("#{key_name}=")
        package.public_send(:"#{key_name}=", value)
      end
    end

    package
  end
end

.push(repo, archive_path) ⇒ Object



100
101
102
103
104
# File 'lib/vx/aptly/package.rb', line 100

def push(repo, archive_path)
  spawn "#{Aptly.root}/bin/vx-aptly push #{repo.name} #{archive_path}" do |re|
    yield re
  end
end

Instance Method Details

#destroy(repo) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/vx/aptly/package.rb', line 49

def destroy(repo)
  line = "aptly repo remove #{repo.name} #{id}"
  capture line do |re|
    @notice = "The command '#{line}' was successfuly finished with output:\n"
    @notice << re
  end
end

#idObject



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

def id
  @id ||= [package, version, architecture].join("_")
end