Class: Sneaql::Core::RepoDownloadManager

Inherits:
Object
  • Object
show all
Defined in:
lib/sneaql_lib/base.rb

Overview

base class for repo managers

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, logger = nil) ⇒ RepoDownloadManager

Returns a new instance of RepoDownloadManager.

Parameters:

  • params (Hash)

    parameters passed to transform will be passed here

  • logger (Logger) (defaults to: nil)

    object otherwise will default to new Logger



204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/sneaql_lib/base.rb', line 204

def initialize(params, logger = nil)
  @logger = logger ? logger : Logger.new(STDOUT)

  @repo_base_dir = "#{params[:repo_base_dir]}/#{params[:transform_name]}"
  @params = params

  # perform the actual actions of managing the repo
  manage_repo
rescue => e
  @logger.error(e.message)
  e.backtrace { |r| @logger.error(r) }
  raise e
end

Instance Attribute Details

#repo_base_dirObject (readonly)

this is the directory that the repo operates in



200
201
202
# File 'lib/sneaql_lib/base.rb', line 200

def repo_base_dir
  @repo_base_dir
end

Instance Method Details

#drop_and_rebuild_directory(directory) ⇒ Object

method to drop and rebuild the specified directory all files and subdirectories will be destroyed

Parameters:

  • directory (String)


221
222
223
224
225
226
227
228
229
# File 'lib/sneaql_lib/base.rb', line 221

def drop_and_rebuild_directory(directory)
  @logger.info("dropping and recreating repo directory #{directory}")
  FileUtils.remove_dir(directory) if Dir.exist?(directory)
  FileUtils.mkdir_p(directory)
rescue => e
  @logger.error(e.message)
  e.backtrace { |r| @logger.error(r) }
  raise e
end

#manage_repoObject

override in your implementation



232
233
234
# File 'lib/sneaql_lib/base.rb', line 232

def manage_repo
  nil
end

#unzip_file(file, destination) ⇒ Object



238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/sneaql_lib/base.rb', line 238

def unzip_file(file, destination)
  ::Zip::ZipFile.open(file) do |zip_file|
    zip_file.each do |f|
      f_path = File.join(destination, f.name)
      FileUtils.mkdir_p(File.dirname(f_path))
      zip_file.extract(f, f_path) unless File.exist?(f_path)
    end
  end
rescue => e
  @logger.error(e.message)
  e.backtrace { |r| @logger.error(r) }
  raise e
end