Method: RokuBuilder::ManifestManager.update_manifest
- Defined in:
- lib/roku_builder/manifest_manager.rb
.update_manifest(root_dir:, attributes:) ⇒ Object
Update attributes in the app manifest It will add missing attributes but not remove them
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/roku_builder/manifest_manager.rb', line 75 def self.update_manifest(root_dir:, attributes:) temp_file = Tempfile.new('manifest') path = File.join(root_dir, 'manifest') new_params = attributes.dup begin if File.exist?(path) File.open(path, 'r') do |file| file.each_line do |line| key = line.split("=")[0] if new_params.include?(key.to_sym) temp_file.puts("#{key}=#{new_params[key.to_sym]}") new_params.delete(key.to_sym) else temp_file.puts(line) end end end else new_params = self.default_params().merge(new_params) end new_params.each_pair do |key, value| temp_file.puts("#{key}=#{value}") end temp_file.rewind FileUtils.cp(temp_file.path, path) ensure temp_file.close temp_file.unlink end end |