class DaFunk::Application
Attributes
crc[RW]
file[R]
label[R]
name[R]
order[R]
original[R]
remote[R]
type[R]
Public Class Methods
delete(collection)
click to toggle source
# File lib/da_funk/application.rb, line 9 def self.delete(collection) collection.each do |app| begin app.delete rescue RuntimeError end end end
new(label, remote, type, crc)
click to toggle source
# File lib/da_funk/application.rb, line 18 def initialize(label, remote, type, crc) @type = type @crc = crc @original = remote @order, @label = split_label(label) company = check_company(remote) @remote = remote.sub("#{company}_", "") @name = remote.sub("#{company}_", "").split(".")[0] @file = check_path("#{@remote}") end
Public Instance Methods
crc_local()
click to toggle source
# File lib/da_funk/application.rb, line 29 def crc_local self.exists? ? @crc_local : nil end
delete()
click to toggle source
# File lib/da_funk/application.rb, line 77 def delete File.delete(self.file) if exists? if self.ruby? && Dir.exist?(self.dir) && self.dir != "main" Zip.clean(self.dir) end end
dir()
click to toggle source
# File lib/da_funk/application.rb, line 69 def dir @name end
download(force = false)
click to toggle source
# File lib/da_funk/application.rb, line 33 def download(force = false) if force || self.outdated? ret = DaFunk::Transaction::Download.request_file(remote, file, self.crc_local) if ret == DaFunk::Transaction::Download::SUCCESS if ((@crc_local = calculate_crc) == @crc) unzip restart else ret = DaFunk::Transaction::Download::COMMUNICATION_ERROR end elsif ret == DaFunk::Transaction::Download::FILE_NOT_CHANGE unzip restart end else ret = DaFunk::Transaction::Download::FILE_NOT_CHANGE end ret rescue => e ContextLog.exception(e, e.backtrace, "Error downloading #{self.name}") DaFunk::Transaction::Download::IO_ERROR end
execute(json = "")
click to toggle source
# File lib/da_funk/application.rb, line 98 def execute(json = "") if posxml? PosxmlInterpreter.new(remote, nil, false).start else Device::Runtime.execute(name, json) end end
exists?()
click to toggle source
# File lib/da_funk/application.rb, line 73 def exists? File.exists?(file) end
main_application?()
click to toggle source
# File lib/da_funk/application.rb, line 94 def main_application? name == 'main' end
outdated?(force = false)
click to toggle source
# File lib/da_funk/application.rb, line 84 def outdated?(force = false) return true unless self.exists? if !self.crc_local || force @crc_local = calculate_crc end self.crc_local != @crc rescue true end
posxml?()
click to toggle source
# File lib/da_funk/application.rb, line 119 def posxml? @type == "posxml" || remote.include?(".posxml") end
restart()
click to toggle source
# File lib/da_funk/application.rb, line 106 def restart stop start end
ruby?()
click to toggle source
# File lib/da_funk/application.rb, line 123 def ruby? @type == "ruby" || (! remote.include? ".posxml") end
start()
click to toggle source
# File lib/da_funk/application.rb, line 115 def start Device::Runtime.start(name) if ruby? && exists? end
stop()
click to toggle source
# File lib/da_funk/application.rb, line 111 def stop Device::Runtime.stop(name) if ruby? && exists? end
unzip()
click to toggle source
# File lib/da_funk/application.rb, line 56 def unzip if self.ruby? zip = self.file message = "Problem to unzip #{zip}[#{name}]" raise FileNotFoundError.new(message) unless self.exists? if main_application? raise ApplicationError.new(message) unless Zip.uncompress(zip, ".", true, false) else raise ApplicationError.new(message) unless Zip.uncompress(zip) end end end
Private Instance Methods
calculate_crc()
click to toggle source
# File lib/da_funk/application.rb, line 133 def calculate_crc if exists? Device::Crypto.file_crc16_hex(file) end end
check_company(name)
click to toggle source
# File lib/da_funk/application.rb, line 129 def check_company(name) name.split("_", 2)[0] end
check_path(path)
click to toggle source
# File lib/da_funk/application.rb, line 139 def check_path(path) if posxml? "./shared/#{path}" else if ruby? "#{path}.zip" else "#{path.to_s.gsub("#{Device::Setting.company_name}_", "")}.zip" end end end
split_label(text)
click to toggle source
# File lib/da_funk/application.rb, line 151 def split_label(text) if text == "X" number, text = 0, "X" else number, text = text.to_s.split(" - ") end if number && text [number.to_i, text.to_s] else [0, text.to_s] end end