Class: Device::Application
- Inherits:
-
Object
- Object
- Device::Application
- Defined in:
- lib/device/application.rb
Instance Attribute Summary collapse
-
#crc ⇒ Object
Returns the value of attribute crc.
-
#crc_local ⇒ Object
readonly
Returns the value of attribute crc_local.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#original ⇒ Object
readonly
Returns the value of attribute original.
-
#remote ⇒ Object
readonly
Returns the value of attribute remote.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #delete ⇒ Object
- #dir ⇒ Object
- #download(force = false) ⇒ Object
- #execute(json = "") ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(label, remote, type, crc) ⇒ Application
constructor
A new instance of Application.
- #outdated? ⇒ Boolean
- #posxml? ⇒ Boolean
- #ruby? ⇒ Boolean
Constructor Details
#initialize(label, remote, type, crc) ⇒ Application
Returns a new instance of Application.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/device/application.rb', line 23 def initialize(label, remote, type, crc) @type = type @crc = crc @original = remote @order, @label = split_label(label) @remote = remote.sub("#{Device::Setting.company_name}_", "") @name = remote.sub("#{Device::Setting.company_name}_", "").split(".")[0] @file = check_path(@remote) @crc_local = @crc if File.exists?(@file) end |
Instance Attribute Details
#crc ⇒ Object
Returns the value of attribute crc.
11 12 13 |
# File 'lib/device/application.rb', line 11 def crc @crc end |
#crc_local ⇒ Object (readonly)
Returns the value of attribute crc_local.
12 13 14 |
# File 'lib/device/application.rb', line 12 def crc_local @crc_local end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
12 13 14 |
# File 'lib/device/application.rb', line 12 def file @file end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
12 13 14 |
# File 'lib/device/application.rb', line 12 def label @label end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/device/application.rb', line 12 def name @name end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
12 13 14 |
# File 'lib/device/application.rb', line 12 def order @order end |
#original ⇒ Object (readonly)
Returns the value of attribute original.
12 13 14 |
# File 'lib/device/application.rb', line 12 def original @original end |
#remote ⇒ Object (readonly)
Returns the value of attribute remote.
12 13 14 |
# File 'lib/device/application.rb', line 12 def remote @remote end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
12 13 14 |
# File 'lib/device/application.rb', line 12 def type @type end |
Class Method Details
.delete(collection) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/device/application.rb', line 14 def self.delete(collection) collection.each do |app| begin app.delete rescue RuntimeError end end end |
Instance Method Details
#delete ⇒ Object
52 53 54 55 56 57 |
# File 'lib/device/application.rb', line 52 def delete File.delete(self.file) if exists? if self.ruby? && Dir.exist?(self.dir) && self.dir != "main" Dir.delete(self.dir) end end |
#dir ⇒ Object
44 45 46 |
# File 'lib/device/application.rb', line 44 def dir @name end |
#download(force = false) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/device/application.rb', line 34 def download(force = false) if force || outdated? ret = Device::Transaction::Download.request_file(remote, file, crc_local) else ret = Device::Transaction::Download::FILE_NOT_CHANGE end @crc_local = @crc if ret == Device::Transaction::Download::SUCCESS ret end |
#execute(json = "") ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/device/application.rb', line 70 def execute(json = "") if posxml? Device::Runtime.execute(remote, json) else Device::Runtime.execute(name, json) end end |
#exists? ⇒ Boolean
48 49 50 |
# File 'lib/device/application.rb', line 48 def exists? File.exists? file end |
#outdated? ⇒ Boolean
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/device/application.rb', line 59 def outdated? return true unless File.exists?(file) unless @crc_local handle = File.open(file) @crc_local = Device::Crypto.crc16_hex(handle.read) end @crc_local != @crc ensure handle.close if handle end |
#posxml? ⇒ Boolean
78 79 80 |
# File 'lib/device/application.rb', line 78 def posxml? @type == "posxml" || remote.include?(".posxml") end |
#ruby? ⇒ Boolean
82 83 84 |
# File 'lib/device/application.rb', line 82 def ruby? @type == "ruby" || (! remote.include? ".posxml") end |