Class: Quik::Package

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

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ Package

e.g. quikstart/gems



7
8
9
10
11
12
13
# File 'lib/quik/package.rb', line 7

def initialize( key )   ## e.g. quikstart/gems
  if key.index( '/' ).nil?  ## if just 'gems' etc; assumbe quikstart "standard" github org
    @key = "quikstart/#{key}"
  else
    @key = key   # use as is e.g. seattlerb/hoe etc.
  end
end

Instance Method Details

#downloadObject



35
36
37
38
39
40
41
42
# File 'lib/quik/package.rb', line 35

def download
  src      = remote_zip_url
  dest_zip = local_zip_path

  ## make sure dest folder exists
  FileUtils.mkdir_p( local_zip_dir ) unless Dir.exist?( local_zip_dir )
  fetch_archive( src, dest_zip )
end

#local_zip_dirObject



25
26
27
# File 'lib/quik/package.rb', line 25

def local_zip_dir
  "."    ## use ./tmp or ./dl  or ~/.quik/cache  - why?? why not??
end

#local_zip_nameObject



20
21
22
23
# File 'lib/quik/package.rb', line 20

def local_zip_name
  ## note: change / to --I-- for "flat" structure (e.g. no dirs)
  @key.sub( '/', '--I--' )   # note: will NOT include/return .zip extension
end

#local_zip_pathObject

local zip path



29
30
31
# File 'lib/quik/package.rb', line 29

def local_zip_path # local zip path
  "#{local_zip_dir}/#{local_zip_name}.zip"
end

#merge(root_dir, hash) ⇒ Object



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

def merge( root_dir, hash )
  ## replace/merge variable in files
  Dir.chdir( "#{root_dir}" ) do
    files = Dir[ '**/*' ]   ## get all files
    pp files
  end
end

#remote_zip_urlObject

remote zip url



16
17
18
# File 'lib/quik/package.rb', line 16

def remote_zip_url # remote zip url
  "https://github.com/#{@key}/archive/master.zip"
end

#unzip(unzip_dir) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/quik/package.rb', line 44

def unzip( unzip_dir )
  src        = local_zip_path
  dest_unzip = unzip_dir ## local_unzip_dir

  ## check if folders exists? if not create folder in path
  FileUtils.mkdir_p( dest_unzip ) unless Dir.exist?( dest_unzip )
  unzip_archive( src, dest_unzip )
end