Created
December 1, 2018 16:37
-
-
Save marzdgzmn/ad3e68c5a36cddaa13db3938d018d5b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
equire_relative 'configuration' | |
require 'ostruct' | |
require 'inifile' | |
module Rise | |
module MirrorManager | |
# Module for Mirror data | |
module Mirror | |
def self.retrieve_mirrors(interval) | |
mirrors = extract_mirrors(Rise::MirrorManager.configuration.mirror_data_file) | |
if mirrors.empty? | |
Rise::MirrorManager.log.error "No mirror configuration was retrieved for interval: #{interval}." | |
exit | |
end | |
mirrors | |
end | |
private | |
def self.extract_mirrors(mirror_data_file) | |
data_file = IniFile.load(mirror_data_file) | |
if data_file.nil? | |
Rise::MirrorManager.log.error "#{mirror_data_file} not found." | |
exit | |
end | |
mirrors = [] | |
data_file.each_section do |section| | |
next if data_file[section]['INTERVAL'] != interval | |
mirror = OpenStruct.new(name: data_file[section]['NAME']) | |
if data_file[section]['SCRIPT'] | |
mirror[:custom_script] = data_file[section]['CUSTOM_SCRIPT'] | |
else | |
mirror[:remote_source] = data_file[section]['REMOTE_SOURCE'] | |
mirror[:local_dir] = data_file[section]['LOCAL_DIR'] | |
mirror[:rsync_opts] = data_file[section]['RSYNC_OPTS'] | |
mirror[:rsync_opts] = data_file[section]['RSYNC_OPTS'] | |
mirror[:rsync_del_opts] = data_file[section]['RSYNC_DEL_OPTS'] | |
mirror[:exclude] = data_file[section]['EXCLUDE'] | |
mirror[:include] = data_file[section]['INCLUDE'] | |
mirror[:filter] = data_file[section]['FILTER'] | |
mirror[:precmd] = data_file[section]['PRECMD'] | |
mirror[:precmd] = data_file[section]['PRECMD'] | |
mirror[:postcmd] = data_file[section]['POSTCMD'] | |
mirror[:depth] = data_file[section]['DEPTH'] | |
end | |
mirrors << mirror | |
end | |
mirrors | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec.describe Rise::MirrorManager::Mirror do | |
it 'should return OpenStruct objects from an INI file' do | |
mirrors = subject.retrieve_mirrors(4) | |
expect(mirrors.name).to equal('Whatever') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment