Class: AndParcel::RemoveRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/andparcel/parcel.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ RemoveRequest

Returns a new instance of RemoveRequest.



438
439
440
441
# File 'lib/andparcel/parcel.rb', line 438

def initialize(opts)
  @opts=opts
  @root=opts[:dir] || '.'
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



436
437
438
# File 'lib/andparcel/parcel.rb', line 436

def opts
  @opts
end

#rootObject (readonly)

Returns the value of attribute root.



436
437
438
# File 'lib/andparcel/parcel.rb', line 436

def root
  @root
end

Instance Method Details

#assets(zf) ⇒ Object



489
490
491
492
493
494
495
496
497
498
499
500
501
# File 'lib/andparcel/parcel.rb', line 489

def assets(zf)
  dir=File.join(@root, 'assets')

  zf.entries.each do |entry|
    if (/^assets\/(.+)$/.match entry.name)
      name=$1
      dest=File.join(dir, File.dirname(name), File.basename(name))
      File.unlink(dest) if File.exists?(dest)
    end
  end
  
  true
end

#libs(zf) ⇒ Object



464
465
466
467
468
469
470
471
472
473
# File 'lib/andparcel/parcel.rb', line 464

def libs(zf)
  zf.entries.each do |entry|
    if ('libs/'==entry.parent_as_string)
      dest=File.join(@root, 'libs', File.basename(entry.name))
      File.unlink(dest) if File.exists?(dest)
    end
  end
  
  true
end

#manifest(zf) ⇒ Object



503
504
# File 'lib/andparcel/parcel.rb', line 503

def manifest(zf)
end

#remove(parcel_name) ⇒ Object



443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
# File 'lib/andparcel/parcel.rb', line 443

def remove(parcel_name)
  @parcel_root=File.join(root, 'parcels', parcel_name)
  
  if File.exists?(@parcel_root)
    dest=Dir[File.join(@parcel_root, '*.zip')][0]
    
    if dest
      Zip::ZipFile.open(dest) do |zf|
        manifest(zf) if
          assets(zf) if
            resources(zf) if
              libs(zf)
      end
      
      FileUtils.rm_rf @parcel_root
    end
  else
    raise "Parcel not installed: #{parcel_name}"
  end
end

#resources(zf) ⇒ Object



475
476
477
478
479
480
481
482
483
484
485
486
487
# File 'lib/andparcel/parcel.rb', line 475

def resources(zf)
  dir=File.join(@root, 'res')

  zf.entries.each do |entry|
    if (/^res\/(.+)$/.match entry.name)
      name=$1
      dest=File.join(dir, File.dirname(name), File.basename(name))
      File.unlink(dest) if File.exists?(dest)
    end
  end
  
  true
end