Class: Sneaql::Core::RepoDownloadManager
- Inherits:
-
Object
- Object
- Sneaql::Core::RepoDownloadManager
- Defined in:
- lib/sneaql_lib/base.rb
Overview
base class for repo managers
Direct Known Subclasses
RepoManagers::GitRepoManager, RepoManagers::HttpStoreRepoManager, RepoManagers::LocalFileSystemRepoManager
Instance Attribute Summary collapse
-
#repo_base_dir ⇒ Object
readonly
this is the directory that the repo operates in.
Instance Method Summary collapse
-
#drop_and_rebuild_directory(directory) ⇒ Object
method to drop and rebuild the specified directory all files and subdirectories will be destroyed.
-
#initialize(params, logger = nil) ⇒ RepoDownloadManager
constructor
A new instance of RepoDownloadManager.
-
#manage_repo ⇒ Object
override in your implementation.
-
#unzip_file(file, destination) ⇒ Object
copied this from the internet www.markhneedham.com/blog/2008/10/02/ruby-unzipping-a-file-using-rubyzip/.
Constructor Details
#initialize(params, logger = nil) ⇒ RepoDownloadManager
Returns a new instance of RepoDownloadManager.
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.) e.backtrace { |r| @logger.error(r) } raise e end |
Instance Attribute Details
#repo_base_dir ⇒ Object (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
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.) e.backtrace { |r| @logger.error(r) } raise e end |
#manage_repo ⇒ Object
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
copied this from the internet www.markhneedham.com/blog/2008/10/02/ruby-unzipping-a-file-using-rubyzip/
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.) e.backtrace { |r| @logger.error(r) } raise e end |