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.
- .read_manifest(root_dir:) ⇒ Object
-
.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
30 31 32 |
# File 'lib/roku_builder/manifest_manager.rb', line 30 def self.build_version(root_dir:) read_manifest(root_dir: root_dir)[:build_version] end |
.default_params ⇒ Hash
Returns the default manafest values
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/roku_builder/manifest_manager.rb', line 95 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 |
.read_manifest(root_dir:) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/roku_builder/manifest_manager.rb', line 34 def self.read_manifest(root_dir:) attrs = {} get_attrs = lambda { |file| file.each_line do |line| key, value = line.split("=") if value attrs[key.chomp.to_sym]= value.chomp elsif key and !key.chomp.empty? attrs[key.chomp.to_sym]= nil end end } if File.directory?(root_dir) path = File.join(root_dir, 'manifest') File.open(path, 'r', &get_attrs) 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_attrs) end end attrs end |
.update_build(root_dir:) ⇒ String
Updates the build version in the manifest file
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/roku_builder/manifest_manager.rb', line 11 def self.update_build(root_dir:) build_version = self.build_version(root_dir: root_dir).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")+".0001" end self.update_manifest(root_dir: root_dir, attributes: {build_version: build_version}) self.build_version(root_dir: root_dir) end |
.update_manifest(root_dir:, attributes:) ⇒ Object
Update attributes in the app manifest It will add missing attributes but not remove them
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/roku_builder/manifest_manager.rb', line 62 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 |