Class: DeployCouch::DeltaLoader
- Inherits:
-
Object
- Object
- DeployCouch::DeltaLoader
- Defined in:
- lib/deploy_couch/delta_loader.rb
Instance Method Summary collapse
- #convert_to_delta(id, file) ⇒ Object
- #get_deltas ⇒ Object
-
#initialize(deltas_folder) ⇒ DeltaLoader
constructor
A new instance of DeltaLoader.
Constructor Details
#initialize(deltas_folder) ⇒ DeltaLoader
Returns a new instance of DeltaLoader.
4 5 6 |
# File 'lib/deploy_couch/delta_loader.rb', line 4 def initialize(deltas_folder) @deltas_folder = deltas_folder end |
Instance Method Details
#convert_to_delta(id, file) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/deploy_couch/delta_loader.rb', line 28 def convert_to_delta(id, file) delta_config = YAML.load_file(file) file_name = File.basename(file) raise "#{file_name} content is not valid " if delta_config['type'].nil? or delta_config['map_function'].nil? Delta.new(id,file_name,delta_config['type'],delta_config['map_function'],delta_config['rollback_function']) end |
#get_deltas ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/deploy_couch/delta_loader.rb', line 8 def get_deltas hash = {} files = Dir["#{@deltas_folder}/*.yml"].select {|f| File.file?(f)} files.each do |file| file_name = File.basename(file) key = file_name.split('_')[0].to_i if (key == 0) e = RuntimeError.new("invalid file name #{file_name}") raise e end if (hash.has_key?(key)) e = RuntimeError.new("duplicate key found in file #{file_name}") raise e end hash[key] = convert_to_delta(key,file) end hash end |