Class: Plasmoid::Package

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

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Package

Returns a new instance of Package.



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

def initialize(filename)
  @filename = filename
  @pkg_name = File.basename(@filename, ".zip")
end

Instance Method Details

#installObject



36
37
38
# File 'lib/plasmoid/package.rb', line 36

def install
  system("plasmapkg -i '#{@filename}'")
end

#runObject



32
33
34
# File 'lib/plasmoid/package.rb', line 32

def run
  system("plasmoidviewer '#{@pkg_name}'")
end

#uninstallObject



40
41
42
# File 'lib/plasmoid/package.rb', line 40

def uninstall
  system("plasmapkg -r '#{@pkg_name}'")
end

#writeObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/plasmoid/package.rb', line 11

def write
  File.unlink(@filename) if File.exist?(@filename)
  Zip::ZipFile.open(@filename, Zip::ZipFile::CREATE) do |zf|
    Find.find(".") do |path|
      path.sub!(/^\.\//, "")

      if path.empty? || path =~ /^\.+$/ || path =~ /\.(zip|haml)$/ || path == "Rakefile"
        next
      end

      if File.directory?(path)
        zf.dir.mkdir(path)
      else
        zf.file.open(path, "w") do |file|
          file.write(File.read(path))
        end
      end
    end
  end
end