Sha256: 6e04fc8514c8237e95d8abe546ce5f27d2a278b25562e506c6bd0e5525a2f807
Contents?: true
Size: 1.99 KB
Versions: 51
Compression:
Stored size: 1.99 KB
Contents
module Helper class Properties attr_accessor :properties_hash attr_accessor :separator def initialize() properties_hash = {} separator = "=" end ### patch properties (key/value) def patch(source, target) if not File.file? source $log.writer.error "File #{source} does not exists" exit 1 end if target.nil? $log.writer.error "Parameter target not set" exit 1 end if target.length == 0 $log.writer.error "Parameter target not set" exit 1 end ### read source file in array data = File.readlines(source) target_file = File.open(target, "w") data.each { |entry| if entry.include? separator keyvalue = entry.split(separator,2) if keyvalue[1].class == TrueClass keyvalue[1] = 'true' end if properties_hash[keyvalue[0].strip].class == TrueClass properties_hash[keyvalue[0].strip] = 'true' end if keyvalue[1].class == FalseClass keyvalue[1] = 'false' end if properties_hash[keyvalue[0].strip].class == FalseClass properties_hash[keyvalue[0].strip] = 'false' end if properties_hash[keyvalue[0].strip] != nil entry = entry.sub(keyvalue[1].strip, properties_hash[keyvalue[0].strip]) end end target_file.puts entry } target_file.close end ### patch strings def substitute(source, target) if not File.file? source $log.writer.error "File #{source} does not exists" exit 1 end ### read backup file in array data = File.readlines(source) target_file = File.open(target, "w") data.each { |entry| properties_hash.keys.each { |hashkey| entry = entry.sub(hashkey, properties_hash[hashkey]) } target_file.puts entry } target_file.close end end end
Version data entries
51 entries across 51 versions & 1 rubygems