Class: RokuBuilder::ManifestManager
- Inherits:
-
Object
- Object
- RokuBuilder::ManifestManager
- Defined in:
- lib/roku_builder/manifest_manager.rb
Overview
Updates or retrives build version
Class Method Summary collapse
-
.build_version(root_dir:) ⇒ String
Retrive the build version from the manifest file.
-
.default_params ⇒ Hash
Returns the default manafest values.
-
.update_build(root_dir:) ⇒ String
Updates the build version in the manifest file.
-
.update_manifest(root_dir:, attributes:) ⇒ Object
Update attributes in the app manifest It will add missing attributes but not remove them.
Class Method Details
.build_version(root_dir:) ⇒ String
Retrive the build version from the manifest file
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/roku_builder/manifest_manager.rb', line 49 def self.build_version(root_dir:) build_version = "" get_version = lambda { |file| file.each_line do |line| if line.include?("build_version") build_version = line.split("=")[1].chomp end end } if File.directory?(root_dir) path = File.join(root_dir, 'manifest') build_version = "" File.open(path, 'r', &get_version) elsif File.extname(root_dir) == ".zip" Zip::File.open(root_dir) do |zip_file| entry = zip_file.glob("manifest").first entry.get_input_stream(&get_version) end end build_version end |
.default_params ⇒ Hash
Returns the default manafest values
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/roku_builder/manifest_manager.rb', line 108 def self.default_params { title: "Default Title", major_version: 1, minor_version: 0, build_version: "010101.0001", mm_icon_focus_hd: "<insert hd focus icon url>", mm_icon_focus_sd: "<insert sd focus icon url>" } end |
.update_build(root_dir:) ⇒ String
Updates the build version in the manifest file
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/roku_builder/manifest_manager.rb', line 9 def self.update_build(root_dir:) build_version = "" temp_file = Tempfile.new('manifest') path = File.join(root_dir, 'manifest') begin File.open(path, 'r') do |file| file.each_line do |line| if line.include?("build_version") #Update build version. build_version = line.split(".") if 2 == build_version.length iteration = build_version[1].to_i + 1 build_version[0] = Time.now.strftime("%m%d%y") build_version[1] = iteration build_version = build_version.join(".") else #Use current date. build_version = Time.now.strftime("%m%d%y")+".1" end temp_file.puts "build_version=#{build_version}" else temp_file.puts line end end end temp_file.rewind FileUtils.cp(temp_file.path, path) ensure temp_file.close temp_file.unlink end build_version end |
.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 |