Class: DrJekyll::Package

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

Instance Method Summary collapse

Constructor Details

#initialize(key, hash) ⇒ Package

note: for now pass in key as its own arg (not part/included in hash)



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/drjekyll/package.rb', line 7

def initialize( key, hash )  ## note: for now pass in key as its own arg (not part/included in hash)

  ##  fix/todo: change key to name - why? why not?
  ##     always downcase key - why? why not?
  ##     convert github e.g owner/repo to ownner--I--repo -- why? why not?
  ##   do NOT pass in hash - just pass in download_url
  ##
  ##  add self.from_github ???  builder/ctor - why? why not?
  ##  add self.from_hash  ??? builder/ctor - why? why not?

  @key  = key
  @hash = hash

  @download_url = @hash['download_url']  # as string
end

Instance Method Details

#downloadObject



41
42
43
44
45
46
47
48
# File 'lib/drjekyll/package.rb', line 41

def download
  src      = remote_zip_url
  dest_zip = local_zip_path

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

#local_zip_dirObject



31
32
33
# File 'lib/drjekyll/package.rb', line 31

def local_zip_dir
  "."    ## use ./tmp or ./dl  or ~/.drjekyll/cache ??
end

#local_zip_nameObject



27
28
29
# File 'lib/drjekyll/package.rb', line 27

def local_zip_name
  @key   # note: will NOT include/return .zip extension
end

#local_zip_pathObject

local zip path



35
36
37
# File 'lib/drjekyll/package.rb', line 35

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

#remote_zip_urlObject

remote zip url



23
24
25
# File 'lib/drjekyll/package.rb', line 23

def remote_zip_url # remote zip url
  @download_url   # as string
end

#unzip(unzip_dir) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/drjekyll/package.rb', line 50

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.exists?( dest_unzip )
  unzip_theme( src, dest_unzip )
end