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 33 |
# File 'lib/device/application.rb', line 23 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) @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
61 62 63 64 65 66 |
# File 'lib/device/application.rb', line 61 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
53 54 55 |
# File 'lib/device/application.rb', line 53 def dir @name end |
#download(force = false) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/device/application.rb', line 35 def download(force = false) if force || self.outdated? ret = Device::Transaction::Download.request_file(remote, file, crc_local) else ret = Device::Transaction::Download::FILE_NOT_CHANGE end if ret == Device::Transaction::Download::SUCCESS @crc_local = calculate_crc if @crc_local != @crc return Device::Transaction::Download::COMMUNICATION_ERROR end end ret rescue => e puts "ERROR #{e.message}" Device::Transaction::Download::IO_ERROR end |
#execute(json = "") ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/device/application.rb', line 76 def execute(json = "") if posxml? PosxmlInterpreter.new(remote, nil, false).start else Device::Runtime.execute(name, json) end end |
#exists? ⇒ Boolean
57 58 59 |
# File 'lib/device/application.rb', line 57 def exists? File.exists? file end |
#outdated? ⇒ Boolean
68 69 70 71 72 73 74 |
# File 'lib/device/application.rb', line 68 def outdated? return true unless File.exists?(file) @crc_local = calculate_crc unless @crc_local @crc_local != @crc rescue true end |
#posxml? ⇒ Boolean
84 85 86 |
# File 'lib/device/application.rb', line 84 def posxml? @type == "posxml" || remote.include?(".posxml") end |
#ruby? ⇒ Boolean
88 89 90 |
# File 'lib/device/application.rb', line 88 def ruby? @type == "ruby" || (! remote.include? ".posxml") end |